#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Point {
pub x: f32,
pub y: f32,
}
impl Point {
pub const fn new(x: f32, y: f32) -> Self {
Point { x, y }
}
pub fn distance(self, other: Point) -> f32 {
let dx = self.x - other.x;
let dy = self.y - other.y;
(dx * dx + dy * dy).sqrt()
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Quad {
pub corners: [Point; 4],
}
impl Quad {
pub const fn new(corners: [Point; 4]) -> Self {
Quad { corners }
}
pub fn bounds(&self) -> (Point, Point) {
let mut min = self.corners[0];
let mut max = self.corners[0];
for c in &self.corners[1..] {
min.x = min.x.min(c.x);
min.y = min.y.min(c.y);
max.x = max.x.max(c.x);
max.y = max.y.max(c.y);
}
(min, max)
}
pub fn center(&self) -> Point {
let (sx, sy) = self
.corners
.iter()
.fold((0.0, 0.0), |(sx, sy), p| (sx + p.x, sy + p.y));
Point::new(sx / 4.0, sy / 4.0)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Location {
pub outline: Quad,
pub rotation: Option<f32>,
pub module_size: Option<f32>,
}