mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-11 21:02:45 +00:00
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 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e977f82558
commit
2fb2689efe
1 file changed
+10
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user