Skip to content

Keep crop finite when crop.set gets a huge rect - #1816

Merged
echelon merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h875-crop-set-with-an-extreme-rect-st
Oct 15, 2026
Merged

echelon merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h875-crop-set-with-an-extreme-rect-st

Conversation

@Silvertree2010

Copy link
Copy Markdown
Contributor

Found while testing crates/geom/src/crop.rs:59 (CropGeometry::constrained, via crates/engine/src/cmd/develop.rs:524 crop.set) (no existing issue): crop.set with an extreme rect stores a NaN crop.

Cause

CropGeometry::constrained shrinks a crop that won't fit by the scale from max_inscribed_scale. For a rect like [0,0,1e308,1e308] the pixel width becomes infinite and that scale becomes 0, so inf * 0 produced a NaN crop, which crop.set then stored and reported as a success.

Fix

If the shrunk crop in constrained has any non-finite coordinate, it now falls back to crop_fit_angle: the largest centred crop that fits at the current angle. That crop keeps the rect's aspect ratio when the ratio is finite, and otherwise uses the image's own.

Verified

  • Regression tests constrained_huge_rect_is_finite_and_inside, crop_set_huge_rect_stays_finite: fail on main without the fix and pass with it (cargo test -p lightcraft-geom constrained_huge_rect_is_finite_and_inside && cargo test -p lightcraft-engine crop_set_huge_rect_stays_finite).
  • cargo xtask ci passes.

Not changed

crop.set still accepts any numbers and doesn't return a validation error. A huge rect is clamped to a finite crop inside the image, as other out-of-range rects already are.

🤖 Generated with Claude Code

Found while testing crates/geom/src/crop.rs:59 (CropGeometry::constrained, via crates/engine/src/cmd/develop.rs:524 crop.set)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
bogusyogi added a commit to Orthic-Labs/ember that referenced this pull request Oct 15, 2026
)

Applied from storytold/lightcraft PR storytold#1816 (open upstream, not yet merged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon
echelon merged commit 33c321c into storytold:main Oct 15, 2026
@echelon

echelon commented Oct 15, 2026

Copy link
Copy Markdown
Member

Thank you @Silvertree2010! This landed on main in integration batch 36 (#1843).

If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants