#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Rect {
pub x: i32,
pub y: i32,
pub w: i32,
pub h: i32,
}
impl Rect {
pub fn shifted(self, dx: i32, dy: i32) -> Self {
Self {
x: self.x + dx,
y: self.y + dy,
..self
}
}
pub fn scaled(self, k: i32) -> Self {
Self {
x: self.x * k,
y: self.y * k,
w: self.w * k,
h: self.h * k,
}
}
pub fn right(self) -> i32 {
self.x + self.w
}
pub fn bottom(self) -> i32 {
self.y + self.h
}
pub fn intersects(self, o: Rect) -> bool {
self.x < o.right() && o.x < self.right() && self.y < o.bottom() && o.y < self.bottom()
}
}