diff --git a/tests/YGRoundingFunctionTest.cpp b/tests/YGRoundingFunctionTest.cpp index 65f487da..e99ced89 100644 --- a/tests/YGRoundingFunctionTest.cpp +++ b/tests/YGRoundingFunctionTest.cpp @@ -80,26 +80,3 @@ TEST(YogaTest, consistent_rounding_during_repeated_layouts) { YGConfigFree(config); } - -// Regression test for https://github.com/facebook/yoga/issues/683 -TEST(YogaTest, negative_value_rounding) { - const YGConfigRef config = YGConfigNew(); - const YGNodeRef root = YGNodeNewWithConfig(config); - const YGNodeRef child = YGNodeNewWithConfig(config); - - YGNodeInsertChild(root, child, 0); - - YGNodeStyleSetWidth(child, 10); - YGNodeStyleSetHeight(child, 10); - YGNodeStyleSetPosition(root, YGEdgeLeft, -0.75f); - YGNodeStyleSetPosition(root, YGEdgeTop, -0.75f); - - YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); - - ASSERT_FLOAT_EQ(YGNodeLayoutGetWidth(child), 10); - ASSERT_FLOAT_EQ(YGNodeLayoutGetHeight(child), 10); - - YGNodeFreeRecursive(root); - - YGConfigFree(config); -} diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 5072992d..2c8f45b0 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3701,12 +3701,16 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( scaledValue = scaledValue - fractial + 1.0; } else if (forceCeil) { // Next we check if we need to use forced rounding - scaledValue = ceil(scaledValue); + scaledValue = scaledValue - fractial + 1.0; } else if (forceFloor) { - scaledValue = floor(scaledValue); + scaledValue = scaledValue - fractial; } else { // Finally we just round the value - scaledValue = round(scaledValue); + scaledValue = scaledValue - fractial + + (!YGDoubleIsUndefined(fractial) && + (fractial > 0.5 || YGDoubleEqual(fractial, 0.5)) + ? 1.0 + : 0.0); } return (YGDoubleIsUndefined(scaledValue) || YGDoubleIsUndefined(pointScaleFactor))