Skip to content

Commit e093cd6

Browse files
committed
Add aabb contains check
1 parent a35ff39 commit e093cd6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

blobs/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ impl AABB {
8989
Self { min, max }
9090
}
9191

92+
pub fn from_center_size(center: Vec2, size: Vec2) -> Self {
93+
let half_size = size * 0.5;
94+
Self {
95+
min: center - half_size,
96+
max: center + half_size,
97+
}
98+
}
99+
92100
pub fn center(&self) -> Vec2 {
93101
(self.min + self.max) * 0.5
94102
}
@@ -97,6 +105,13 @@ impl AABB {
97105
self.max - self.min
98106
}
99107

108+
pub fn contains(&self, point: Vec2) -> bool {
109+
self.min.x <= point.x
110+
&& self.min.y <= point.y
111+
&& self.max.x >= point.x
112+
&& self.max.y >= point.y
113+
}
114+
100115
pub fn expand_to_include_point(&mut self, point: Vec2) {
101116
self.min = self.min.min(point);
102117
self.max = self.max.max(point);

0 commit comments

Comments
 (0)