use crate::*;
pub trait Lerpable {
fn lerp(&self,to:Self,lerp:f32) -> Self;
}
impl <A> Lerpable for A
where A: Clone
+ Add<Output=A>
+ Sub<Output=A>
+ Mul<f32,Output=A>
{
fn lerp(&self,to:Self,lerp:f32) -> Self {
self.clone().add(to.sub(self.clone()).mul(lerp))
}
}
pub trait LerpableF32 {
fn lerp(&self,to:Self,lerp:f32) -> Self;
}
impl <A> LerpableF32 for A
where A: Clone
+ Add<Output=A>
+ Sub<Output=A>
+ MulF32
{
fn lerp(&self,to:Self,lerp:f32) -> Self {
self.clone().add(to.sub(self.clone()).mul_f32(lerp))
}
}
pub trait Glerpable {
fn glerp(&mut self,to:Self,lerp:f32,thresh:Self) -> bool;
}
buns::sandwich!{
impl Glerpable for ^0 {
#[inline]
fn glerp(&mut self,to:Self,lerp:f32,thresh:Self) -> bool {
let delta = to - *self;
if delta.abs() <= thresh || lerp >= 1. {
*self = to;
true
} else {
*self += delta.mul_f32(lerp);
false
}
}
}
#f32 #f64 #i8 #i16 #i32 #i64 #i128 #isize
}
pub trait Clerpable {
fn delta_qucy(&self,to:Self,min:Self,max:Self) -> Self;
fn lerp_qucy(&self,to:Self,lerp:f32,min:Self,max:Self) -> Self;
fn glerp_qucy(&mut self,to:Self,lerp:f32,thresh:Self,min:Self,max:Self) -> bool;
}
buns::sandwich!{
impl Clerpable for ^0 {
#[inline]
fn delta_qucy(&self,to:Self,min:Self,max:Self) -> Self {
let delta = to - *self;
let deltabs = delta.abs();
let dolta = max - min - deltabs;
if deltabs < dolta {delta} else {-dolta * delta.signum()}
}
#[inline]
fn lerp_qucy(&self,to:Self,lerp:f32,min:Self,max:Self) -> Self {
let delta = self.delta_qucy(to,min,max);
self.add_qucy((delta as f32 * lerp) as ^0,min,max)
}
#[inline]
fn glerp_qucy(&mut self,to:Self,lerp:f32,thresh:Self,min:Self,max:Self) -> bool {
let delta = self.delta_qucy(to,min,max);
if delta.abs() <= thresh || lerp >= 1. {
*self = to;
true
} else {
*self = self.add_qucy(delta.mul_f32(lerp),min,max);
false
}
}
}
#f32 #f64 #i8 #i16 #i32 #i64 #i128 #isize
}