mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Fix intersects_rect ignoring paths crossing zero-width/height rects
Found while testing crates/geom/src/hit.rs:116 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:
committed by
bflatastic
co-authored by
Claude Haiku 5.5
parent
cb631ae635
commit
ec4975f237
+12
-1
@@ -119,7 +119,8 @@ pub fn stroke_contains(path: &BezPath, width: f64, tol: f64, p: Point) -> bool {
|
||||
/// (#1103).
|
||||
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 degenerate = |x: Rect| x.width() == 0.0 || x.height() == 0.0;
|
||||
if b.intersect(r).area() <= 0.0 && !degenerate(b) && !degenerate(r) {
|
||||
return false;
|
||||
}
|
||||
// Any anchor inside?
|
||||
@@ -227,6 +228,16 @@ 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 marquee_degenerate_rect() {
|
||||
let p = shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.0));
|
||||
// zero-height / zero-width marquee crossing the shape
|
||||
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)));
|
||||
// zero-height marquee missing it
|
||||
assert!(!intersects_rect(&p, Rect::new(20.0, 5.0, 30.0, 5.0)));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user