mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-11 21:02:45 +00:00
Merge pull request #2437 from Silvertree2010/fix/h8141-hit-intersects-rect-returns-fals
Normalize marquee rect in hit::intersects_rect
This commit is contained in:
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