From 70369ae5d38f9a52eae25f620f923945bf0b172d Mon Sep 17 00:00:00 2001 From: Jonathan Maurice Date: Tue, 19 Dec 2017 11:47:55 -0500 Subject: [PATCH 1/2] Fix negative value rounding issue for nodes across an axis --- yoga/Yoga.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 3ccd103c10..ab9e0ecf48 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3015,13 +3015,12 @@ float YGRoundValueToPixelGrid(const float value, scaledValue = scaledValue - fractial + 1.0; } else if (forceCeil) { // Next we check if we need to use forced rounding - scaledValue = scaledValue - fractial + 1.0f; + scaledValue = ceilf(scaledValue); } else if (forceFloor) { - scaledValue = scaledValue - fractial; + scaledValue = floorf(scaledValue); } else { // Finally we just round the value - scaledValue = scaledValue - fractial + - (fractial > 0.5f || YGFloatsEqual(fractial, 0.5f) ? 1.0f : 0.0f); + scaledValue = roundf(scaledValue); } return scaledValue / pointScaleFactor; } From d5d05a40ed1f97347de097107001bf683684c4d3 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Tue, 24 Jan 2023 09:59:27 -0500 Subject: [PATCH 2/2] Switch from float to double rounding functions --- yoga/Yoga.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index c8cef8eb9a..5072992d9c 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3701,12 +3701,12 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( scaledValue = scaledValue - fractial + 1.0; } else if (forceCeil) { // Next we check if we need to use forced rounding - scaledValue = ceilf(scaledValue); + scaledValue = ceil(scaledValue); } else if (forceFloor) { - scaledValue = floorf(scaledValue); + scaledValue = floor(scaledValue); } else { // Finally we just round the value - scaledValue = roundf(scaledValue); + scaledValue = round(scaledValue); } return (YGDoubleIsUndefined(scaledValue) || YGDoubleIsUndefined(pointScaleFactor))