#[derive(Default, Clone, Copy, Debug)]
pub struct Rectangle(pub f32, pub f32, pub f32, pub f32);
impl Rectangle {
pub fn new(xy: (f32, f32), wh: (f32, f32)) -> Self {
Self(xy.0, xy.1, wh.0, wh.1)
}
pub fn new_scaled(view: (f32, f32), xy: (f32, f32), wh: (f32, f32)) -> Self {
Self(
(xy.0 / view.0) * 2.0 + (wh.0 / view.0) - 1.0,
1.0 - (wh.1 / view.1) - (xy.1 / view.1) * 2.0,
wh.0 / view.0,
wh.1 / view.1
)
}
pub fn interescts(&self, p: (f32, f32)) -> bool {
p.0 >= self.0 && p.0 <= self.0 + self.2
&& p.1 >= self.1 && p.1 <= self.1 + self.3
}
pub fn xy(&self) -> (f32, f32) {
(self.0, self.1)
}
pub fn wh(&self) -> (f32, f32) {
(self.2, self.3)
}
}