both YGRoundToPixelGrid and YGRoundValueToPixelGrid accumulated errror #901

Open
opened 2019-06-11 04:33:33 -07:00 by carlhuting · 2 comments
carlhuting commented 2019-06-11 04:33:33 -07:00 (Migrated from github.com)

Report

Issues and Steps to Reproduce

Replaces this with steps to repro your issue.
node {
position = 5 5 0 0
dimensions = 365, 252
}
NodeType = Text;
others pading boder margin = 0;
pointScaleFactor = 3
absoluteLeft = 5
absoluteTop = 411.666656

1 YGRoundToPixelGrid

const float absoluteNodeTop = absoluteTop + nodeTop;
const float absoluteNodeBottom = absoluteNodeTop + nodeHeight;
const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) &&
!YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0);
node->setLayoutDimension(
YGRoundValueToPixelGrid(
absoluteNodeBottom,
pointScaleFactor,
(textRounding && hasFractionalHeight),
(textRounding && !hasFractionalHeight)) -
YGRoundValueToPixelGrid(
absoluteNodeTop, pointScaleFactor, false, textRounding),
YGDimensionHeight);
This is unreasonable, maybe we just want YGRoundValueToPixelGrid(nodeHeight);

2 YGRoundValueToPixelGrid
used too much YGFloatsEqual

bool YGFloatsEqual(const float a, const float b) { if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) { return fabs(a - b) < 0.0001f; } return YGFloatIsUndefined(a) && YGFloatIsUndefined(b); }
screen one pixel is not < 0.0001f, nicer precision at this place is 1/pointScaleFactor

Expected Behavior

Describe what you expected would happen.
nodeHeight beginWith 252 ,after 251.666656
Except nodeHeight never lost precision

Actual Behavior

Describe what actually happened.

Link to Code

19035c90e9

When applicable, use this fiddle to post a web repro.

# Report - [Y] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate # Issues and Steps to Reproduce ***Replaces this with steps to repro your issue.*** node { position = 5 5 0 0 dimensions = 365, 252 } NodeType = Text; others pading boder margin = 0; pointScaleFactor = 3 absoluteLeft = 5 absoluteTop = 411.666656 1 YGRoundToPixelGrid const float **absoluteNodeTop** = absoluteTop + nodeTop; const float **absoluteNodeBottom** = **absoluteNodeTop** + nodeHeight; const bool hasFractionalHeight = !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) && !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0); node->setLayoutDimension( YGRoundValueToPixelGrid( **absoluteNodeBottom**, pointScaleFactor, (textRounding && hasFractionalHeight), (textRounding && !hasFractionalHeight)) - YGRoundValueToPixelGrid( **absoluteNodeTop**, pointScaleFactor, false, textRounding), YGDimensionHeight); This is unreasonable, maybe we just want YGRoundValueToPixelGrid(nodeHeight); 2 YGRoundValueToPixelGrid used too much `YGFloatsEqual` ` bool YGFloatsEqual(const float a, const float b) { if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) { return fabs(a - b) < 0.0001f; } return YGFloatIsUndefined(a) && YGFloatIsUndefined(b); } ` screen one pixel is not < 0.0001f, nicer precision at this place is 1/pointScaleFactor # Expected Behavior ***Describe what you expected would happen.*** nodeHeight beginWith 252 ,after 251.666656 Except nodeHeight never lost precision # Actual Behavior ***Describe what actually happened.*** # Link to Code https://github.com/facebook/yoga/pull/902/commits/19035c90e9107226cc53d91f6722ee331339624a ***When applicable, use this [fiddle](https://jsfiddle.net/emilsjolander/jckmwztt/) to post a web repro.***
carlhuting commented 2019-06-12 01:37:09 -07:00 (Migrated from github.com)

see my MR

see my [MR](https://github.com/facebook/yoga/pull/902/commits/19035c90e9107226cc53d91f6722ee331339624a)
ktuan89 commented 2020-02-10 14:46:44 -08:00 (Migrated from github.com)

Ping! I have the same issue with my project and the above pull request ^ fixes the issue. It would be great if any active maintainer of this project can fix it

Ping! I have the same issue with my project and the above pull request ^ fixes the issue. It would be great if any active maintainer of this project can fix it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#901
No description provided.