pico_detect/traits/
region.rs1use nalgebra::Point2;
2
3pub trait Region {
5 fn left(&self) -> i32;
7 fn top(&self) -> i32;
9 fn width(&self) -> u32;
11 fn height(&self) -> u32;
13
14 #[inline]
16 fn right(&self) -> i32 {
17 self.left() + (self.width() - 1) as i32
18 }
19
20 #[inline]
22 fn bottom(&self) -> i32 {
23 self.top() + (self.height() - 1) as i32
24 }
25
26 #[inline]
28 fn is_square(&self) -> bool {
29 self.width() == self.height()
30 }
31
32 #[inline]
34 fn contains(&self, x: i32, y: i32) -> bool {
35 self.left() <= x && self.top() <= y && self.right() >= x && self.bottom() >= y
36 }
37
38 #[inline]
40 fn center(&self) -> Point2<i32> {
41 Point2::new(
42 self.left() + (self.width() / 2 + 1) as i32,
43 self.top() + (self.height() / 2 + 1) as i32,
44 )
45 }
46
47 #[inline]
49 fn top_left(&self) -> Point2<i32> {
50 Point2::new(self.left(), self.top())
51 }
52
53 #[inline]
55 fn square(&self) -> u32 {
56 self.width() * self.height()
57 }
58}