2 * Copyright (c) 2014-present, Facebook, Inc.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
10 YGFlexDirection YGFlexDirectionCross(
11 const YGFlexDirection flexDirection,
12 const YGDirection direction) {
13 return YGFlexDirectionIsColumn(flexDirection)
14 ? YGResolveFlexDirection(YGFlexDirectionRow, direction)
15 : YGFlexDirectionColumn;
18 float YGFloatMax(const float a, const float b) {
19 if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
22 return YGFloatIsUndefined(a) ? b : a;
25 float YGFloatMin(const float a, const float b) {
26 if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
30 return YGFloatIsUndefined(a) ? b : a;
33 bool YGValueEqual(const YGValue a, const YGValue b) {
34 if (a.unit != b.unit) {
38 if (a.unit == YGUnitUndefined ||
39 (YGFloatIsUndefined(a.value) && YGFloatIsUndefined(b.value))) {
43 return fabs(a.value - b.value) < 0.0001f;
46 bool YGFloatsEqual(const float a, const float b) {
47 if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
48 return fabs(a - b) < 0.0001f;
50 return YGFloatIsUndefined(a) && YGFloatIsUndefined(b);
53 float YGFloatSanitize(const float& val) {
54 return YGFloatIsUndefined(val) ? 0 : val;
57 float YGUnwrapFloatOptional(const YGFloatOptional& op) {
58 return op.isUndefined() ? YGUndefined : op.getValue();
61 YGFloatOptional YGFloatOptionalMax(
62 const YGFloatOptional& op1,
63 const YGFloatOptional& op2) {
64 if (!op1.isUndefined() && !op2.isUndefined()) {
65 return op1.getValue() > op2.getValue() ? op1 : op2;
67 return op1.isUndefined() ? op2 : op1;