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
This commit is contained in:
Sidharth Guglani 2020-04-27 14:38:51 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 702ff6d1cd
Коммит fc5a626e38
2 изменённых файлов: 15 добавлений и 15 удалений

Просмотреть файл

@ -3664,8 +3664,8 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid(
} }
YOGA_EXPORT float YGRoundValueToPixelGrid( YOGA_EXPORT float YGRoundValueToPixelGrid(
const float value, const double value,
const float pointScaleFactor, const double pointScaleFactor,
const bool forceCeil, const bool forceCeil,
const bool forceFloor) { const bool forceFloor) {
double scaledValue = ((double) value) * pointScaleFactor; double scaledValue = ((double) value) * pointScaleFactor;
@ -4081,24 +4081,24 @@ YOGA_EXPORT void YGConfigSetPointScaleFactor(
static void YGRoundToPixelGrid( static void YGRoundToPixelGrid(
const YGNodeRef node, const YGNodeRef node,
const float pointScaleFactor, const double pointScaleFactor,
const float absoluteLeft, const double absoluteLeft,
const float absoluteTop) { const double absoluteTop) {
if (pointScaleFactor == 0.0f) { if (pointScaleFactor == 0.0f) {
return; return;
} }
const float nodeLeft = node->getLayout().position[YGEdgeLeft]; const double nodeLeft = node->getLayout().position[YGEdgeLeft];
const float nodeTop = node->getLayout().position[YGEdgeTop]; const double nodeTop = node->getLayout().position[YGEdgeTop];
const float nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; const double nodeWidth = node->getLayout().dimensions[YGDimensionWidth];
const float nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; const double nodeHeight = node->getLayout().dimensions[YGDimensionHeight];
const float absoluteNodeLeft = absoluteLeft + nodeLeft; const double absoluteNodeLeft = absoluteLeft + nodeLeft;
const float absoluteNodeTop = absoluteTop + nodeTop; const double absoluteNodeTop = absoluteTop + nodeTop;
const float absoluteNodeRight = absoluteNodeLeft + nodeWidth; const double absoluteNodeRight = absoluteNodeLeft + nodeWidth;
const float absoluteNodeBottom = absoluteNodeTop + nodeHeight; const double absoluteNodeBottom = absoluteNodeTop + nodeHeight;
// If a node has a custom measure function we never want to round down its // If a node has a custom measure function we never want to round down its
// size as this could lead to unwanted text truncation. // size as this could lead to unwanted text truncation.

Просмотреть файл

@ -352,8 +352,8 @@ WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context);
WIN_EXPORT void* YGConfigGetContext(YGConfigRef config); WIN_EXPORT void* YGConfigGetContext(YGConfigRef config);
WIN_EXPORT float YGRoundValueToPixelGrid( WIN_EXPORT float YGRoundValueToPixelGrid(
float value, double value,
float pointScaleFactor, double pointScaleFactor,
bool forceCeil, bool forceCeil,
bool forceFloor); bool forceFloor);