mirror of
https://github.com/ratatui-org/ratatui
synced 2024-09-20 14:42:06 +00:00
fix(Rect): fix underflow in the Rect::intersection
method (#678)
This commit is contained in:
parent
2a87251152
commit
f69d57c3b5
1 changed files with 10 additions and 2 deletions
|
@ -155,8 +155,8 @@ impl Rect {
|
|||
Rect {
|
||||
x: x1,
|
||||
y: y1,
|
||||
width: x2 - x1,
|
||||
height: y2 - y1,
|
||||
width: x2.saturating_sub(x1),
|
||||
height: y2.saturating_sub(y1),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,6 +280,14 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersection_underflow() {
|
||||
assert_eq!(
|
||||
Rect::new(1, 1, 2, 2).intersection(Rect::new(4, 4, 2, 2)),
|
||||
Rect::new(4, 4, 0, 0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersects() {
|
||||
assert!(Rect::new(1, 2, 3, 4).intersects(Rect::new(2, 3, 4, 5)));
|
||||
|
|
Loading…
Reference in a new issue