Skip to content

Commit d3398c5

Browse files
authored
Add Rect::intersect test (#562)
This particular case came up, [#vello > vello sparse strips v0.0.7 @ 💬](https://xi.zulipchat.com/#narrow/channel/197075-vello/topic/vello.20sparse.20strips.20v0.2E0.2E7/near/581539227), and we may as well add it to the tests.
1 parent 04543e7 commit d3398c5

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

kurbo/src/rect.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,4 +1032,22 @@ mod tests {
10321032
let inner = Rect::new(11.0, 11.0, 15.0, 15.0);
10331033
assert!(!outer.contains_rect(inner));
10341034
}
1035+
1036+
#[test]
1037+
fn rect_intersect_zero() {
1038+
// These rectangles don't overlap vertically.
1039+
let a = Rect::new(25., 101., 200., 130.);
1040+
let b = Rect::new(0., 0., 100., 100.);
1041+
1042+
for intersection in [a.intersect(b), b.intersect(a)] {
1043+
assert_eq!(intersection.x0, 25.);
1044+
assert_eq!(intersection.x1, 100.);
1045+
assert_eq!(intersection.area(), 0.);
1046+
assert_eq!(intersection.y0, intersection.y1);
1047+
1048+
// We don't guarantee this in the documentation, but the intersection's `y` values should
1049+
// be a sensible value taken from the input.
1050+
assert!([0., 100., 101., 130.].contains(&intersection.y0));
1051+
}
1052+
}
10351053
}

0 commit comments

Comments
 (0)