Skip to content

Commit 2b173ff

Browse files
committed
make intersect inclusive
1 parent 812db47 commit 2b173ff

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

crates/yakui-core/src/geometry/rect.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,14 @@ impl Rect {
103103

104104
/// Tells whether two rectangles intersect.
105105
///
106-
/// If the rectangles touch but do not overlap, they are considered **not
107-
/// intersecting**.
106+
/// If the rectangles touch but do not overlap, they are still considered **intersecting**.
108107
#[inline]
109108
pub fn intersects(&self, other: &Self) -> bool {
110109
let self_max = self.max();
111110
let other_max = other.max();
112111

113-
let x_intersect = self.pos.x < other_max.x && self_max.x > other.pos.x;
114-
let y_intersect = self.pos.y < other_max.y && self_max.y > other.pos.y;
112+
let x_intersect = self.pos.x <= other_max.x && self_max.x >= other.pos.x;
113+
let y_intersect = self.pos.y <= other_max.y && self_max.y >= other.pos.y;
115114

116115
x_intersect && y_intersect
117116
}

crates/yakui-core/src/geometry/urect.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ impl URect {
107107

108108
/// Tells whether two rectangles intersect.
109109
///
110-
/// If the rectangles touch but do not overlap, they are considered **not
111-
/// intersecting**.
110+
/// If the rectangles touch but do not overlap, they are still considered **intersecting**.
112111
#[inline]
113112
pub fn intersects(&self, other: &Self) -> bool {
114113
let self_max = self.max();
115114
let other_max = other.max();
116115

117-
let x_intersect = self.pos.x < other_max.x && self_max.x > other.pos.x;
118-
let y_intersect = self.pos.y < other_max.y && self_max.y > other.pos.y;
116+
let x_intersect = self.pos.x <= other_max.x && self_max.x >= other.pos.x;
117+
let y_intersect = self.pos.y <= other_max.y && self_max.y >= other.pos.y;
119118

120119
x_intersect && y_intersect
121120
}

0 commit comments

Comments
 (0)