use core::ops::AddAssign;
pub trait Interpolatable: Default + Clone {
fn add_with_weight(&mut self, src: &Self, weight: f32);
}
impl Interpolatable for f32 {
#[inline]
fn add_with_weight(&mut self, src: &Self, weight: f32) {
*self += src * weight;
}
}
impl Interpolatable for f64 {
#[inline]
fn add_with_weight(&mut self, src: &Self, weight: f32) {
*self += *src * weight as f64;
}
}
impl<const N: usize> Interpolatable for [f32; N]
where
[f32; N]: Default,
{
#[inline]
fn add_with_weight(&mut self, src: &Self, weight: f32) {
self.iter_mut()
.zip(src.iter())
.for_each(|(dst, s)| dst.add_assign(s * weight));
}
}
impl<const N: usize> Interpolatable for [f64; N]
where
[f64; N]: Default,
{
#[inline]
fn add_with_weight(&mut self, src: &Self, weight: f32) {
let w = weight as f64;
self.iter_mut()
.zip(src.iter())
.for_each(|(dst, s)| dst.add_assign(s * w));
}
}