diff --git a/ReactCommon/yoga/yoga/Utils.cpp b/ReactCommon/yoga/yoga/Utils.cpp index 5f6c960d4..839952219 100644 --- a/ReactCommon/yoga/yoga/Utils.cpp +++ b/ReactCommon/yoga/yoga/Utils.cpp @@ -7,6 +7,8 @@ */ #include "Utils.h" +using namespace facebook; + YGFlexDirection YGFlexDirectionCross( const YGFlexDirection flexDirection, const YGDirection direction) { @@ -16,18 +18,18 @@ YGFlexDirection YGFlexDirectionCross( } float YGFloatMax(const float a, const float b) { - if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) { + if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { return fmaxf(a, b); } - return YGFloatIsUndefined(a) ? b : a; + return yoga::isUndefined(a) ? b : a; } float YGFloatMin(const float a, const float b) { - if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) { + if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { return fminf(a, b); } - return YGFloatIsUndefined(a) ? b : a; + return yoga::isUndefined(a) ? b : a; } bool YGValueEqual(const YGValue a, const YGValue b) { @@ -36,7 +38,7 @@ bool YGValueEqual(const YGValue a, const YGValue b) { } if (a.unit == YGUnitUndefined || - (YGFloatIsUndefined(a.value) && YGFloatIsUndefined(b.value))) { + (yoga::isUndefined(a.value) && yoga::isUndefined(b.value))) { return true; } @@ -44,14 +46,14 @@ bool YGValueEqual(const YGValue a, const YGValue b) { } bool YGFloatsEqual(const float a, const float b) { - if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) { + if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { return fabs(a - b) < 0.0001f; } - return YGFloatIsUndefined(a) && YGFloatIsUndefined(b); + return yoga::isUndefined(a) && yoga::isUndefined(b); } float YGFloatSanitize(const float& val) { - return YGFloatIsUndefined(val) ? 0 : val; + return yoga::isUndefined(val) ? 0 : val; } float YGUnwrapFloatOptional(const YGFloatOptional& op) { diff --git a/ReactCommon/yoga/yoga/YGFloatOptional.cpp b/ReactCommon/yoga/yoga/YGFloatOptional.cpp index d3407fa23..cb867f3ac 100644 --- a/ReactCommon/yoga/yoga/YGFloatOptional.cpp +++ b/ReactCommon/yoga/yoga/YGFloatOptional.cpp @@ -9,9 +9,12 @@ #include #include #include "Yoga.h" +#include "Yoga-internal.h" + +using namespace facebook; YGFloatOptional::YGFloatOptional(float value) { - if (YGFloatIsUndefined(value)) { + if (yoga::isUndefined(value)) { isUndefined_ = true; value_ = 0; } else { @@ -41,7 +44,7 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const { } bool YGFloatOptional::operator==(float val) const { - if (YGFloatIsUndefined(val) == isUndefined_) { + if (yoga::isUndefined(val) == isUndefined_) { return isUndefined_ || val == value_; } return false; diff --git a/ReactCommon/yoga/yoga/YGLayout.cpp b/ReactCommon/yoga/yoga/YGLayout.cpp index 604d7109c..dfd7be08b 100644 --- a/ReactCommon/yoga/yoga/YGLayout.cpp +++ b/ReactCommon/yoga/yoga/YGLayout.cpp @@ -8,6 +8,8 @@ #include "YGLayout.h" #include "Utils.h" +using namespace facebook; + const std::array kYGDefaultDimensionValues = { {YGUndefined, YGUndefined}}; @@ -46,13 +48,13 @@ bool YGLayout::operator==(YGLayout layout) const { isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i]; } - if (!YGFloatIsUndefined(measuredDimensions[0]) || - !YGFloatIsUndefined(layout.measuredDimensions[0])) { + if (!yoga::isUndefined(measuredDimensions[0]) || + !yoga::isUndefined(layout.measuredDimensions[0])) { isEqual = isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]); } - if (!YGFloatIsUndefined(measuredDimensions[1]) || - !YGFloatIsUndefined(layout.measuredDimensions[1])) { + if (!yoga::isUndefined(measuredDimensions[1]) || + !yoga::isUndefined(layout.measuredDimensions[1])) { isEqual = isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]); } diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index 9e7a182b7..70dd655da 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -9,6 +9,8 @@ #include #include "Utils.h" +using namespace facebook; + YGFloatOptional YGNode::getLeadingPosition( const YGFlexDirection& axis, const float& axisSize) const { @@ -500,7 +502,7 @@ bool YGNode::isNodeFlexible() { float YGNode::getLeadingBorder(const YGFlexDirection& axis) const { if (YGFlexDirectionIsRow(axis) && style_.border[YGEdgeStart].unit != YGUnitUndefined && - !YGFloatIsUndefined(style_.border[YGEdgeStart].value) && + !yoga::isUndefined(style_.border[YGEdgeStart].value) && style_.border[YGEdgeStart].value >= 0.0f) { return style_.border[YGEdgeStart].value; } @@ -513,7 +515,7 @@ float YGNode::getLeadingBorder(const YGFlexDirection& axis) const { float YGNode::getTrailingBorder(const YGFlexDirection& flexDirection) const { if (YGFlexDirectionIsRow(flexDirection) && style_.border[YGEdgeEnd].unit != YGUnitUndefined && - !YGFloatIsUndefined(style_.border[YGEdgeEnd].value) && + !yoga::isUndefined(style_.border[YGEdgeEnd].value) && style_.border[YGEdgeEnd].value >= 0.0f) { return style_.border[YGEdgeEnd].value; } diff --git a/ReactCommon/yoga/yoga/Yoga-internal.h b/ReactCommon/yoga/yoga/Yoga-internal.h index 84c4596bc..941147e87 100644 --- a/ReactCommon/yoga/yoga/Yoga-internal.h +++ b/ReactCommon/yoga/yoga/Yoga-internal.h @@ -24,6 +24,26 @@ WIN_EXPORT float YGRoundValueToPixelGrid( YG_EXTERN_C_END +namespace facebook { +namespace yoga { + +inline bool isUndefined(float value) { + // Value of a float in the case of it being not defined is 10.1E20. Earlier + // it used to be NAN, the benefit of which was that if NAN is involved in any + // mathematical expression the result was NAN. But since we want to have + // `-ffast-math` flag being used by compiler which assumes that the floating + // point values are not NAN and Inf, we represent YGUndefined as 10.1E20. But + // now if YGUndefined is involved in any mathematical operations this + // value(10.1E20) would change. So the following check makes sure that if the + // value is outside a range (-10E8, 10E8) then it is undefined. + return value >= 10E8 || value <= -10E8; +} + +} // namespace yoga +} // namespace facebook + +using namespace facebook; + extern const std::array trailing; extern const std::array leading; extern bool YGValueEqual(const YGValue a, const YGValue b); @@ -63,20 +83,20 @@ struct YGCachedMeasurement { bool isEqual = widthMeasureMode == measurement.widthMeasureMode && heightMeasureMode == measurement.heightMeasureMode; - if (!YGFloatIsUndefined(availableWidth) || - !YGFloatIsUndefined(measurement.availableWidth)) { + if (!yoga::isUndefined(availableWidth) || + !yoga::isUndefined(measurement.availableWidth)) { isEqual = isEqual && availableWidth == measurement.availableWidth; } - if (!YGFloatIsUndefined(availableHeight) || - !YGFloatIsUndefined(measurement.availableHeight)) { + if (!yoga::isUndefined(availableHeight) || + !yoga::isUndefined(measurement.availableHeight)) { isEqual = isEqual && availableHeight == measurement.availableHeight; } - if (!YGFloatIsUndefined(computedWidth) || - !YGFloatIsUndefined(measurement.computedWidth)) { + if (!yoga::isUndefined(computedWidth) || + !yoga::isUndefined(measurement.computedWidth)) { isEqual = isEqual && computedWidth == measurement.computedWidth; } - if (!YGFloatIsUndefined(computedHeight) || - !YGFloatIsUndefined(measurement.computedHeight)) { + if (!yoga::isUndefined(computedHeight) || + !yoga::isUndefined(measurement.computedHeight)) { isEqual = isEqual && computedHeight == measurement.computedHeight; } diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 1ea109e29..fe4192073 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -104,15 +104,7 @@ static int YGDefaultLog(const YGConfigRef config, #endif bool YGFloatIsUndefined(const float value) { - // Value of a float in the case of it being not defined is 10.1E20. Earlier - // it used to be NAN, the benefit of which was that if NAN is involved in any - // mathematical expression the result was NAN. But since we want to have - // `-ffast-math` flag being used by compiler which assumes that the floating - // point values are not NAN and Inf, we represent YGUndefined as 10.1E20. But - // now if YGUndefined is involved in any mathematical operations this - // value(10.1E20) would change. So the following check makes sure that if the - // value is outside a range (-10E8, 10E8) then it is undefined. - return value >= 10E8 || value <= -10E8; + return facebook::yoga::isUndefined(value); } const YGValue* YGComputedEdgeValue(