#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Rect {
pub x: i32,
pub y: i32,
pub width: i32,
pub height: i32,
}
impl Rect {
pub const fn new(x: i32, y: i32, width: i32, height: i32) -> Self {
Self {
x,
y,
width,
height,
}
}
pub fn intersects(&self, other: &Rect) -> bool {
self.x < other.x + other.width
&& self.x + self.width > other.x
&& self.y < other.y + other.height
&& self.y + self.height > other.y
}
pub fn contains(&self, px: i32, py: i32) -> bool {
self.x <= px && self.x + self.width > px && self.y <= py && self.y + self.height > py
}
pub fn area(&self) -> i64 {
i64::from(self.width) * i64::from(self.height)
}
}