2019-04-21 18:11:06 +02:00
|
|
|
use cgmath::{BaseFloat, BaseNum, InnerSpace, Quaternion, VectorSpace, Vector1, Vector2, Vector3, Vector4};
|
2019-04-19 15:45:27 +02:00
|
|
|
|
2019-04-21 18:11:06 +02:00
|
|
|
use crate::interpolate::{Additive, Interpolate, Linear, One, cubic_hermite_def};
|
2019-04-19 15:45:27 +02:00
|
|
|
|
|
|
|
macro_rules! impl_interpolate_vec {
|
2019-04-21 18:11:06 +02:00
|
|
|
($($t:tt)*) => {
|
|
|
|
impl<T> Linear<T> for $($t)*<T> where T: BaseNum {
|
|
|
|
fn outer_mul(self, t: T) -> Self {
|
|
|
|
self * t
|
|
|
|
}
|
|
|
|
|
|
|
|
fn outer_div(self, t: T) -> Self {
|
|
|
|
self / t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Interpolate<T> for $($t)*<T> where Self: InnerSpace<Scalar = T>, T: Additive + BaseFloat + One {
|
|
|
|
fn lerp(a: Self, b: Self, t: T) -> Self {
|
2019-04-19 15:45:27 +02:00
|
|
|
a.lerp(b, t)
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:11:06 +02:00
|
|
|
fn cubic_hermite(x: (Self, T), a: (Self, T), b: (Self, T), y: (Self, T), t: T) -> Self {
|
2019-04-19 15:45:27 +02:00
|
|
|
cubic_hermite_def(x, a, b, y, t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:11:06 +02:00
|
|
|
impl_interpolate_vec!(Vector1);
|
|
|
|
impl_interpolate_vec!(Vector2);
|
|
|
|
impl_interpolate_vec!(Vector3);
|
|
|
|
impl_interpolate_vec!(Vector4);
|
|
|
|
|
|
|
|
impl<T> Linear<T> for Quaternion<T> where T: BaseFloat {
|
|
|
|
fn outer_mul(self, t: T) -> Self {
|
|
|
|
self * t
|
|
|
|
}
|
|
|
|
|
|
|
|
fn outer_div(self, t: T) -> Self {
|
|
|
|
self / t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Interpolate<T> for Quaternion<T> where Self: InnerSpace<Scalar = T>, T: Additive + BaseFloat + One {
|
|
|
|
fn lerp(a: Self, b: Self, t: T) -> Self {
|
|
|
|
a.nlerp(b, t)
|
|
|
|
}
|
2019-04-19 15:45:27 +02:00
|
|
|
|
2019-04-21 18:11:06 +02:00
|
|
|
fn cubic_hermite(x: (Self, T), a: (Self, T), b: (Self, T), y: (Self, T), t: T) -> Self {
|
|
|
|
cubic_hermite_def(x, a, b, y, t)
|
|
|
|
}
|
|
|
|
}
|