Skip to content

Fix Rectangle::chord endpoint distance for diagonal angles - #3529

Open
akasakariko wants to merge 1 commit into
iced-rs:masterfrom
akasakariko:fix-chord-endpoint-distance
Open

akasakariko wants to merge 1 commit into
iced-rs:masterfrom
akasakariko:fix-chord-endpoint-distance

Conversation

@akasakariko

Copy link
Copy Markdown

Fixes #3504

Rectangle::chord computed the half-length as max(|r.x| * width / 2, |r.y| * height / 2), which is not a ray/box intersection. For diagonal angles this placed endpoints inside the rectangle, or outside it for non-square bounds, so linear gradients were compressed or overflowed

The half-length is now min((width / 2) / |r.x|, (height / 2) / |r.y|), with infinities when a component is zero, so both endpoints always lie on the boundary

  • 100x100 at 45 degrees: (25, 75) -> (75, 25) becomes (0, 100) -> (100, 0)
  • 100x20 at 45 degrees: (25, 35) -> (75, -15) becomes (40, 20) -> (60, 0)
  • 0 and 90 degree chords are unchanged

A regression test in core/src/rectangle.rs covers axis-aligned and diagonal chords

Local checks

  • cargo test -p iced_core
  • cargo fmt --all -- --check
  • RUSTFLAGS="--deny warnings" cargo clippy -p iced_core --all-targets
  • RUSTFLAGS="--deny warnings" cargo check -p iced_graphics -p iced_tiny_skia

Compute the half-length as the minimum of the ray intersection
distances with the rectangle slabs instead of the maximum of the
projected half-extents

This puts both endpoints on the boundary for non-axis-aligned
angles and leaves axis-aligned chords unchanged
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.

Fix Rectangle::chord endpoint distance for diagonal angles

1 participant