use num_traits::Float;
pub trait Cubic {
fn map_cubic(&self) -> Self;
}
impl Cubic for f32 {
fn map_cubic(&self) -> Self {
let x = self.clamp(0.0, 1.0);
x * x * (3.0 - (x * 2.0))
}
}
impl Cubic for f64 {
fn map_cubic(&self) -> Self {
let x = self.clamp(0.0, 1.0);
x * x * (3.0 - (x * 2.0))
}
}
impl<T> Cubic for [T; 2]
where
T: Float + Cubic,
{
fn map_cubic(&self) -> Self {
[self[0].map_cubic(), self[1].map_cubic()]
}
}
impl<T> Cubic for [T; 3]
where
T: Float + Cubic,
{
fn map_cubic(&self) -> Self {
[
self[0].map_cubic(),
self[1].map_cubic(),
self[2].map_cubic(),
]
}
}
impl<T> Cubic for [T; 4]
where
T: Float + Cubic,
{
fn map_cubic(&self) -> Self {
[
self[0].map_cubic(),
self[1].map_cubic(),
self[2].map_cubic(),
self[3].map_cubic(),
]
}
}