From ff0a3f39d9c67ee27eb8055698a5eec75a336040 Mon Sep 17 00:00:00 2001 From: Chandra Patni Date: Wed, 1 Nov 2017 15:42:41 -0700 Subject: [PATCH] use `> || YGFloatsEqual` instead of `>=` for computing round value to pixel grid Summary: YGRoundValueToPixelGrid does not handle float point values correctly. It causes layout bugs in arm 32 devices. The way values are rounded to pixel grid is the following: if value is close to the left pixel - discard error and set it equal to left pixel. If value is close to right pixel - set it equal to the right pixel. Otherwise if value is closer to the left - set it equal to the left, closer to the right - set it equal to the right. The problem is when values are close to the middle. Old implementation could produce either left or right boundaries. This patch moves all values that are close to the middle to right boundary. This way results are consistent. Reviewed By: emilsjolander Differential Revision: D6202484 fbshipit-source-id: bb80235452208caec388775574cc4f07bfd649c4 --- yoga/Yoga.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 9486724b..45b37b9d 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -3322,7 +3322,7 @@ float YGRoundValueToPixelGrid(const float value, scaledValue = scaledValue - fractial; } else { // Finally we just round the value - scaledValue = scaledValue - fractial + (fractial >= 0.5f ? 1.0f : 0.0f); + scaledValue = scaledValue - fractial + (fractial > 0.5f || YGFloatsEqual(fractial, 0.5f) ? 1.0f : 0.0f); } return scaledValue / pointScaleFactor; }