From ca483cae0002bb9e1190d8fa7392d560183c7ff4 Mon Sep 17 00:00:00 2001 From: Marco Cova Date: Sat, 10 Jun 2017 05:30:17 -0700 Subject: [PATCH] Rounding error in width/height fixed Summary: If the width has an exact dimension, while the left and right edges have a decimal part, that means the decimal part is equal and we can round both down instead of rounding left down and right up. Same for top and bottom. Reviewed By: emilsjolander Differential Revision: D5209073 Tags: accept2ship fbshipit-source-id: a3a6a43767aa707ebfa5eee62a83adcdd88d7ce6 --- yoga/Yoga.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 5ed9e1af..96c6c5a5 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -3456,11 +3456,22 @@ static void YGRoundToPixelGrid(const YGNodeRef node, node->layout.position[YGEdgeTop] = YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding); + const bool hasFractionalWidth = !YGFloatsEqual(fmodf(nodeWidth, 1.0), 0); + const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight, 1.0), 0); + node->layout.dimensions[YGDimensionWidth] = - YGRoundValueToPixelGrid(absoluteNodeRight, pointScaleFactor, textRounding, false) - + YGRoundValueToPixelGrid( + absoluteNodeRight, + pointScaleFactor, + (textRounding && hasFractionalWidth), + (textRounding && !hasFractionalWidth)) - YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, textRounding); node->layout.dimensions[YGDimensionHeight] = - YGRoundValueToPixelGrid(absoluteNodeBottom, pointScaleFactor, textRounding, false) - + YGRoundValueToPixelGrid( + absoluteNodeBottom, + pointScaleFactor, + (textRounding && hasFractionalHeight), + (textRounding && !hasFractionalHeight)) - YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, textRounding); const uint32_t childCount = YGNodeListCount(node->children);