use super::scalar::lerp_scalar;
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct Point2 {
x: f32,
y: f32,
}
impl Point2 {
#[must_use]
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
#[must_use]
pub const fn x(&self) -> f32 {
self.x
}
#[must_use]
pub const fn y(&self) -> f32 {
self.y
}
}
pub fn interp_path(from: &[Point2], to: &[Point2], mix: f32, out: &mut [Point2]) -> usize {
let mut written = 0_usize;
for (index, from_point) in from.iter().enumerate() {
let Some(to_point) = to.get(index) else {
break;
};
let Some(slot) = out.get_mut(index) else {
break;
};
*slot = Point2::new(
lerp_scalar(from_point.x, to_point.x, mix),
lerp_scalar(from_point.y, to_point.y, mix),
);
written = written.saturating_add(1);
}
written
}