From 2fb2689efedda11909a8aa0dbb5c1869a0082a25 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 7 Nov 2026 11:14:34 +0100 Subject: [PATCH] Normalize marquee rect in hit::intersects_rect Found while testing crates/geom/src/hit.rs:28-35 (intersects_rect: `path.anchors().any(|(_, _, a)| r.contains(a.p))` and the early-out using `b.intersect(r)`) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/geom/src/hit.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/geom/src/hit.rs b/crates/geom/src/hit.rs index 096e0e1e3..feb770e47 100644 --- a/crates/geom/src/hit.rs +++ b/crates/geom/src/hit.rs @@ -26,6 +26,7 @@ pub fn stroke_contains(path: &BezPath, width: f64, tol: f64, p: Point) -> bool { /// Does the path intersect (or lie inside) the rect? Used for marquee selection. pub fn intersects_rect(path: &PathData, r: Rect) -> bool { + let r = r.abs(); let Some(b) = path.bounds() else { return false }; let flat = |q: Rect| q.width() == 0.0 || q.height() == 0.0; if b.intersect(r).area() <= 0.0 && !flat(b) && !flat(r) { @@ -92,6 +93,15 @@ mod tests { assert!(intersects_rect(&l, Rect::new(4.0, 0.0, 6.0, 10.0))); } + #[test] + fn reversed_marquee() { + let p = shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.0)); + assert!(intersects_rect(&p, Rect::new(15.0, 15.0, 5.0, 5.0))); + assert!(intersects_rect(&p, Rect::new(15.0, 5.0, 5.0, 15.0))); + assert!(intersects_rect(&p, Rect::new(6.0, 6.0, 4.0, 4.0))); + assert!(!intersects_rect(&p, Rect::new(30.0, 30.0, 20.0, 20.0))); + } + #[test] fn flat_marquee() { let p = shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.0));