From 5d75c7c4c8095a033ba77045aba197dc122de7cf Mon Sep 17 00:00:00 2001 From: Georgiy Kassabli Date: Wed, 12 Jul 2017 09:27:51 -0700 Subject: [PATCH] Fixing the issue with node dimensions rounding in Yoga Summary: Yoga had a bug in Rounding calculation that caused text nodes dimensions to be rounded up even when the dimensions didn't need rounding Reviewed By: emilsjolander Differential Revision: D5406211 fbshipit-source-id: df1d54ed0805dfc3abbd8f0ceae30f6d8c26d61a --- yoga/Yoga.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 68009fd8..398d3774 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -3474,8 +3474,12 @@ static void YGRoundToPixelGrid(const YGNodeRef node, node->layout.position[YGEdgeTop] = YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding); - const bool hasFractionalWidth = !YGFloatsEqual(fmodf(nodeWidth, 1 / pointScaleFactor), 0); - const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight, 1 / pointScaleFactor), 0); + // We multiply dimension by scale factor and if the result is close to the whole number, we don't have any fraction + // To verify if the result is close to whole number we want to check both floor and ceil numbers + const bool hasFractionalWidth = !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 0) && + !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 1.0); + const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) && + !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0); node->layout.dimensions[YGDimensionWidth] = YGRoundValueToPixelGrid(