Coverage Report

Created: 2026-08-13 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/yoga/yoga/algorithm/BoundAxis.h
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
8
#pragma once
9
10
#include <yoga/algorithm/FlexDirection.h>
11
#include <yoga/enums/Dimension.h>
12
#include <yoga/enums/FlexDirection.h>
13
#include <yoga/node/Node.h>
14
#include <yoga/numeric/Comparison.h>
15
#include <yoga/numeric/FloatOptional.h>
16
17
namespace facebook::yoga {
18
19
inline float paddingAndBorderForAxis(
20
    const yoga::Node* const node,
21
    const FlexDirection axis,
22
    const Direction direction,
23
74.0M
    const float widthSize) {
24
74.0M
  return node->style().computeInlineStartPaddingAndBorder(
25
74.0M
             axis, direction, widthSize) +
26
74.0M
      node->style().computeInlineEndPaddingAndBorder(
27
74.0M
          axis, direction, widthSize);
28
74.0M
}
29
30
inline FloatOptional boundAxisWithinMinAndMax(
31
    const yoga::Node* const node,
32
    const Direction direction,
33
    const FlexDirection axis,
34
    const FloatOptional value,
35
    const float axisSize,
36
88.2M
    const float widthSize) {
37
88.2M
  FloatOptional min;
38
88.2M
  FloatOptional max;
39
40
88.2M
  if (isColumn(axis)) {
41
35.8M
    min = node->style().resolvedMinDimension(
42
35.8M
        direction, Dimension::Height, axisSize, widthSize);
43
35.8M
    max = node->style().resolvedMaxDimension(
44
35.8M
        direction, Dimension::Height, axisSize, widthSize);
45
52.4M
  } else if (isRow(axis)) {
46
52.4M
    min = node->style().resolvedMinDimension(
47
52.4M
        direction, Dimension::Width, axisSize, widthSize);
48
52.4M
    max = node->style().resolvedMaxDimension(
49
52.4M
        direction, Dimension::Width, axisSize, widthSize);
50
52.4M
  }
51
52
88.2M
  if (max >= FloatOptional{0} && value > max) {
53
0
    return max;
54
0
  }
55
56
88.2M
  if (min >= FloatOptional{0} && value < min) {
57
0
    return min;
58
0
  }
59
60
88.2M
  return value;
61
88.2M
}
62
63
// Like boundAxisWithinMinAndMax but also ensures that the value doesn't
64
// go below the padding and border amount.
65
inline float boundAxis(
66
    const yoga::Node* const node,
67
    const FlexDirection axis,
68
    const Direction direction,
69
    const float value,
70
    const float axisSize,
71
50.7M
    const float widthSize) {
72
50.7M
  return yoga::maxOrDefined(
73
50.7M
      boundAxisWithinMinAndMax(
74
50.7M
          node, direction, axis, FloatOptional{value}, axisSize, widthSize)
75
50.7M
          .unwrap(),
76
50.7M
      paddingAndBorderForAxis(node, axis, direction, widthSize));
77
50.7M
}
78
79
} // namespace facebook::yoga