use crate::{Centi, Point, PointScaler};
#[derive(Default, Debug, Copy, Clone, PartialEq)]
pub struct Bounds<P: PointScaler = Centi> {
pub min: Point<P>,
pub max: Point<P>,
}
impl<P: PointScaler> Bounds<P> {
#[must_use]
pub fn new(x: f64, y: f64) -> Self {
Self {
min: Point::new(0.0, 0.0),
max: Point::new(x, y),
}
}
#[must_use]
pub fn minmax() -> Self {
Self {
min: Point::MAX,
max: Point::MIN,
}
}
#[must_use]
pub fn size(&self) -> Point<P> {
Point::new(self.max.x() - self.min.x(), self.max.y() - self.min.y())
}
#[must_use]
pub fn center(&self) -> Point<P> {
let size = self.size();
Point::new(self.min.x() + size.x() / 2.0, self.min.y() + size.y() / 2.0)
}
}