-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Describe the bug
With a specific ContentSize, the computed CropSize becomes incorrect due to floating-point precision issues.
To Reproduce
This issue reproduces 100% with the following conditions:
ContentSize = (402, 674)- Run on an iPhone 16 Pro (physical device with screen width = 402)
(The simulator does reproduce the bug.)
I’ve attached a reproduction file:
bug.patch
Observed result:
CropSize = (401, 402)
Expected behavior
The expected computed size should be:
(402, 402)
iOS Device:
- Device: iPhone 16 Pro
- Reproducible: 100%
Additional context
Although minor, this issue creates a subtle 1-pixel line at the bottom of the crop view in my UI.
Suggest fix
Current computation:
cropBoxSize = (CGSize){fullSizeRatio.width * fitScale, fullSizeRatio.height * fitScale};
Updated version to avoid floating-point artifacts:
cropBoxSize = (CGSize){roundf(fullSizeRatio.width * fitScale), roundf(fullSizeRatio.height * fitScale)};
Proposed patch:
fix.patch
The root cause is the floating-point evaluation:
cropBoxSize = (402.00000000000006, 402.00000000000006)
After combined ceilf / floorf operations, this can produce a 1-pixel delta on real devices.
