use std::ops::{Add, Div, Mul, Sub};
use rand_distr::{Distribution, Normal};
#[derive(Debug, Clone, Copy)]
pub struct Coordinate {
pub x: f64,
pub y: f64,
}
impl Coordinate {
pub(crate) fn add_jitter(&self, std_dev: f64) -> Self {
let normal = Normal::new(0.0, std_dev).unwrap();
let jitter = Coordinate {
x: normal.sample(&mut rand::rng()),
y: normal.sample(&mut rand::rng()),
};
*self + jitter
}
pub(crate) fn lerp(&self, other: &Self, t: f64) -> Self {
Self {
x: self.x + t * (other.x - self.x),
y: self.y + t * (other.y - self.y),
}
}
}
impl Add for Coordinate {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
}
impl Div<f64> for Coordinate {
type Output = Self;
fn div(self, rhs: f64) -> Self::Output {
Self {
x: self.x / rhs,
y: self.y / rhs,
}
}
}
impl Mul<f64> for Coordinate {
type Output = Self;
fn mul(self, rhs: f64) -> Self::Output {
Self {
x: self.x * rhs,
y: self.y * rhs,
}
}
}
impl Sub for Coordinate {
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
Self {
x: self.x - rhs.x,
y: self.y - rhs.y,
}
}
}