-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
width calculation error after setting flexBasis and flexWrap attribute #838
Comments
I noticed something similar when creating an
If there wasn't any precision error on the original stack layout's height, this wouldn't happen:
Would this be a reasonable change to ASCeilPixelValue?
Or is that too hacky and heavy handed? |
@rcancro Maybe I know how to solve this problem. Although he still sometimes has the problem mentioned above, it is much better. Maybe we shouldn't use percentages to set the width. It's probably a good idea to use |
I think we're definitely dealing with an issue caused by floating points precision on 3x devices. I think a solution along the line of @rcancro's is the best we can do. @rcancro Any reason to disregard the trailing bits of CGFloat ASCeilPixelValue(CGFloat f)
{
CGFloat scale = ASScreenScale();
return ceil((f - FLT_EPSILON) * scale) / scale;
} Edit: Another solution is to use CGFloat ASCeilPixelValue(CGFloat f)
{
CGFloat scale = ASScreenScale();
return ceilf(f * scale) / scale;
} |
I agree this is better:
I think we'd want to stay in double if possible. Converting from double to a float will still put us in a position where we are trying to put more precision into a float than it can handle. Look at these examples: The last digit of the float is still not what we want. Another idea is we may be able to decide how many decimal points we think are significant and compute based on those. For example, if we want 5 digits of layout precision we could try:
As long as we require less precision than double/float can give us, we should avoid the precision errors at the end (I hope?). |
@rcancro I agree with either of your solutions, although for simplicity, I'd prefer the first one ( |
Layouts can come back for 3x devices as a repeating decimal. Floats/doubles have a hard time representing these values and often the last digit or two will be garbage. This garbage can result in unexpected values from `ceil` or `round`. I try to fix this by subtracting `FLT_EPSILON` from the value before calling `ceil` or `round` TextureGroup#838
* [Issue 838] Update ASCeilPixelValue and ASRoundPixelValue Layouts can come back for 3x devices as a repeating decimal. Floats/doubles have a hard time representing these values and often the last digit or two will be garbage. This garbage can result in unexpected values from `ceil` or `round`. I try to fix this by subtracting `FLT_EPSILON` from the value before calling `ceil` or `round` #838 * addressed comments on the pr
…up#864) * [Issue 838] Update ASCeilPixelValue and ASRoundPixelValue Layouts can come back for 3x devices as a repeating decimal. Floats/doubles have a hard time representing these values and often the last digit or two will be garbage. This garbage can result in unexpected values from `ceil` or `round`. I try to fix this by subtracting `FLT_EPSILON` from the value before calling `ceil` or `round` TextureGroup#838 * addressed comments on the pr
AsyncDisplayKit some Waring
Width calculation error after setting flexBasis attribute
I don’t know if I’m dealing with this issue
When I set flexWrap using ASStackLayoutSpec I found this problem. In the end I found out that because of the calculation, the width was out of range. This main problem appears in the following code
ASInternalHelpers ASCeilPixelValue
For example
in iPhoneX, the width is 375 and flexBasis is set to 0.5. The scale is 3.
The result is 186.666666666666....
Caused the width to exceed 375
Reproduce this problem
AsyncCeilWidthError
The text was updated successfully, but these errors were encountered: