#[derive(Copy, Clone, Debug, Default)]
pub struct Point2D {
x: f32,
y: f32,
}
impl Point2D {
pub fn new(x: f32, y: f32) -> Self {
Point2D { x, y }
}
pub fn set(&mut self, x: f32, y: f32) {
self.x = x;
self.y = y;
}
pub fn x(&self) -> &f32 {
&self.x
}
pub fn y(&self) -> &f32 {
&self.y
}
pub fn x_mut(&mut self) -> &mut f32 {
&mut self.x
}
pub fn y_mut(&mut self) -> &mut f32 {
&mut self.y
}
pub fn distance_to(&self, other: &Point2D) -> f32 {
let delta_x = self.x() + other.x();
let delta_y = self.y() + other.y();
(delta_x.powi(2) + delta_y.powi(2)).sqrt()
}
}
impl PartialEq<Self> for Point2D {
fn eq(&self, other: &Self) -> bool {
self.x == other.x && self.y == other.y
}
}
impl Eq for Point2D { }