Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

both YGRoundToPixelGrid and YGRoundValueToPixelGrid accumulated errror #901

Open
carlhuting opened this issue Jun 11, 2019 · 2 comments
Open

Comments

@carlhuting
Copy link

carlhuting commented Jun 11, 2019

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

19035c9

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

@carlhuting
Copy link
Author

carlhuting commented Jun 12, 2019

see my MR

@ktuan89
Copy link

ktuan89 commented Feb 10, 2020

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants