tree: implement pointer constraints
This commit is contained in:
parent
d4c4497043
commit
38d1267ec9
19 changed files with 707 additions and 4 deletions
16
src/rect.rs
16
src/rect.rs
|
|
@ -118,6 +118,22 @@ impl Rect {
|
|||
self.raw.x1 <= x && self.raw.y1 <= y && self.raw.x2 > x && self.raw.y2 > y
|
||||
}
|
||||
|
||||
pub fn dist_squared(&self, x: i32, y: i32) -> i32 {
|
||||
let mut dx = 0;
|
||||
if self.raw.x1 > x {
|
||||
dx = self.raw.x1 - x;
|
||||
} else if self.raw.x2 < x {
|
||||
dx = x - self.raw.x1;
|
||||
}
|
||||
let mut dy = 0;
|
||||
if self.raw.y1 > y {
|
||||
dy = self.raw.y1 - y;
|
||||
} else if self.raw.y2 < y {
|
||||
dy = y - self.raw.y1;
|
||||
}
|
||||
dx * dx + dy * dy
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn contains_rect(&self, rect: &Self) -> bool {
|
||||
self.raw.x1 <= rect.raw.x1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue