Skip to content

Minor bug on a specific view size causing incorrect CropSize #637

Description

@vubaone

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)

Screenshots
Image

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions