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
This commit is contained in:
Marco Cova
2017-06-10 05:30:17 -07:00
committed by Facebook Github Bot
parent a20bde8444
commit ca483cae00

View File

@@ -3456,11 +3456,22 @@ static void YGRoundToPixelGrid(const YGNodeRef node,
node->layout.position[YGEdgeTop] = node->layout.position[YGEdgeTop] =
YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, textRounding); 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] = node->layout.dimensions[YGDimensionWidth] =
YGRoundValueToPixelGrid(absoluteNodeRight, pointScaleFactor, textRounding, false) - YGRoundValueToPixelGrid(
absoluteNodeRight,
pointScaleFactor,
(textRounding && hasFractionalWidth),
(textRounding && !hasFractionalWidth)) -
YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, textRounding); YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, textRounding);
node->layout.dimensions[YGDimensionHeight] = node->layout.dimensions[YGDimensionHeight] =
YGRoundValueToPixelGrid(absoluteNodeBottom, pointScaleFactor, textRounding, false) - YGRoundValueToPixelGrid(
absoluteNodeBottom,
pointScaleFactor,
(textRounding && hasFractionalHeight),
(textRounding && !hasFractionalHeight)) -
YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, textRounding); YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, textRounding);
const uint32_t childCount = YGNodeListCount(node->children); const uint32_t childCount = YGNodeListCount(node->children);