Avoid calling fmod twice in roundLayoutResultsToPixelGrid #1775

Closed
rshest wants to merge 1 commits from export-D67689065 into main

View File

@@ -66,7 +66,8 @@ void roundLayoutResultsToPixelGrid(
yoga::Node* const node, yoga::Node* const node,
const double absoluteLeft, const double absoluteLeft,
const double absoluteTop) { const double absoluteTop) {
const auto pointScaleFactor = node->getConfig()->getPointScaleFactor(); const auto pointScaleFactor =
static_cast<double>(node->getConfig()->getPointScaleFactor());
const double nodeLeft = node->getLayout().position(PhysicalEdge::Left); const double nodeLeft = node->getLayout().position(PhysicalEdge::Left);
const double nodeTop = node->getLayout().position(PhysicalEdge::Top); const double nodeTop = node->getLayout().position(PhysicalEdge::Top);
@@ -80,7 +81,7 @@ void roundLayoutResultsToPixelGrid(
const double absoluteNodeRight = absoluteNodeLeft + nodeWidth; const double absoluteNodeRight = absoluteNodeLeft + nodeWidth;
const double absoluteNodeBottom = absoluteNodeTop + nodeHeight; const double absoluteNodeBottom = absoluteNodeTop + nodeHeight;
if (pointScaleFactor != 0.0f) { if (pointScaleFactor != 0.0) {
// 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.
const bool textRounding = node->getNodeType() == NodeType::Text; const bool textRounding = node->getNodeType() == NodeType::Text;
@@ -96,12 +97,14 @@ void roundLayoutResultsToPixelGrid(
// We multiply dimension by scale factor and if the result is close to the // 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 // 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 // to whole number we want to check both floor and ceil numbers
const double scaledNodeWith = nodeWidth * pointScaleFactor;
const bool hasFractionalWidth = const bool hasFractionalWidth =
!yoga::inexactEquals(fmod(nodeWidth * pointScaleFactor, 1.0), 0) && !yoga::inexactEquals(round(scaledNodeWith), scaledNodeWith);
!yoga::inexactEquals(fmod(nodeWidth * pointScaleFactor, 1.0), 1.0);
const double scaledNodeHeight = nodeHeight * pointScaleFactor;
const bool hasFractionalHeight = const bool hasFractionalHeight =
!yoga::inexactEquals(fmod(nodeHeight * pointScaleFactor, 1.0), 0) && !yoga::inexactEquals(round(scaledNodeHeight), scaledNodeHeight);
!yoga::inexactEquals(fmod(nodeHeight * pointScaleFactor, 1.0), 1.0);
node->setLayoutDimension( node->setLayoutDimension(
roundValueToPixelGrid( roundValueToPixelGrid(