From 83b27417ae6a1d577b1fddfa3c9433c2dc42a460 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Mon, 27 Apr 2020 14:38:51 -0700 Subject: [PATCH] Fix rounding error using double instead of float Summary: Changelog: [Internal] [Yoga] Use double instead of float during rounding process to prevent loss of precision. Reviewed By: mdvacca Differential Revision: D21227565 fbshipit-source-id: 380b57535a356624cda8dc2017871a4ef3c882d1 --- yoga/Yoga.cpp | 26 +++++++++++++------------- yoga/Yoga.h | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index bb7da7bf..c2a5c286 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3664,8 +3664,8 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid( } YOGA_EXPORT float YGRoundValueToPixelGrid( - const float value, - const float pointScaleFactor, + const double value, + const double pointScaleFactor, const bool forceCeil, const bool forceFloor) { double scaledValue = ((double) value) * pointScaleFactor; @@ -4081,24 +4081,24 @@ YOGA_EXPORT void YGConfigSetPointScaleFactor( static void YGRoundToPixelGrid( const YGNodeRef node, - const float pointScaleFactor, - const float absoluteLeft, - const float absoluteTop) { + const double pointScaleFactor, + const double absoluteLeft, + const double absoluteTop) { if (pointScaleFactor == 0.0f) { return; } - const float nodeLeft = node->getLayout().position[YGEdgeLeft]; - const float nodeTop = node->getLayout().position[YGEdgeTop]; + const double nodeLeft = node->getLayout().position[YGEdgeLeft]; + const double nodeTop = node->getLayout().position[YGEdgeTop]; - const float nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; - const float nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; + const double nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; + const double nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; - const float absoluteNodeLeft = absoluteLeft + nodeLeft; - const float absoluteNodeTop = absoluteTop + nodeTop; + const double absoluteNodeLeft = absoluteLeft + nodeLeft; + const double absoluteNodeTop = absoluteTop + nodeTop; - const float absoluteNodeRight = absoluteNodeLeft + nodeWidth; - const float absoluteNodeBottom = absoluteNodeTop + nodeHeight; + const double absoluteNodeRight = absoluteNodeLeft + nodeWidth; + const double absoluteNodeBottom = absoluteNodeTop + nodeHeight; // If a node has a custom measure function we never want to round down its // size as this could lead to unwanted text truncation. diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 2fe60a41..87901a28 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -352,8 +352,8 @@ WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context); WIN_EXPORT void* YGConfigGetContext(YGConfigRef config); WIN_EXPORT float YGRoundValueToPixelGrid( - float value, - float pointScaleFactor, + double value, + double pointScaleFactor, bool forceCeil, bool forceFloor);