Fix intersects_rect missing hits for zero-width/height marquee rects

Found while testing crates/geom/src/hit.rs:32-35 (intersects_rect early-out)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-31 06:47:04 +01:00
co-authored by Claude Haiku 5.5
parent ea214dd44d
commit aa449aa358
+10 -1
View File
@@ -27,7 +27,8 @@ 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 Some(b) = path.bounds() else { return false };
if b.intersect(r).area() <= 0.0 && !(b.width() == 0.0 || b.height() == 0.0) {
let flat = |q: Rect| q.width() == 0.0 || q.height() == 0.0;
if b.intersect(r).area() <= 0.0 && !flat(b) && !flat(r) {
return false;
}
// Any anchor inside?
@@ -90,4 +91,12 @@ mod tests {
let l = shapes::line(Point::new(0.0, 0.0), Point::new(10.0, 10.0));
assert!(intersects_rect(&l, Rect::new(4.0, 0.0, 6.0, 10.0)));
}
#[test]
fn flat_marquee() {
let p = shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.0));
assert!(intersects_rect(&p, Rect::new(-5.0, 5.0, 15.0, 5.0)));
assert!(intersects_rect(&p, Rect::new(5.0, -5.0, 5.0, 15.0)));
assert!(!intersects_rect(&p, Rect::new(-5.0, 20.0, 15.0, 20.0)));
}
}