#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct Rect {
pub x: usize,
pub y: usize,
pub width: usize,
pub height: usize,
}
impl Rect {
pub fn new(x: usize, y: usize, width: usize, height: usize) -> Self {
Self {
x,
y,
width,
height,
}
}
pub fn contains(&self, x: u32, y: u32) -> bool {
let x = x as usize;
let y = y as usize;
x >= self.x
&& x < self.x.saturating_add(self.width)
&& y >= self.y
&& y < self.y.saturating_add(self.height)
}
pub fn area(&self) -> usize {
self.width.saturating_mul(self.height)
}
}