2019-04-21 18:12:04 +02:00
|
|
|
use cgmath::{
|
2019-04-21 18:17:01 +02:00
|
|
|
BaseFloat, BaseNum, InnerSpace, Quaternion, Vector1, Vector2, Vector3, Vector4
|
2019-04-21 18:12:04 +02:00
|
|
|
};
|
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 {
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 18:11:06 +02:00
|
|
|
fn outer_mul(self, t: T) -> Self {
|
|
|
|
self * t
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 18:11:06 +02:00
|
|
|
fn outer_div(self, t: T) -> Self {
|
|
|
|
self / t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:12:04 +02:00
|
|
|
impl<T> Interpolate<T> for $($t)*<T>
|
|
|
|
where Self: InnerSpace<Scalar = T>, T: Additive + BaseFloat + One {
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 18:11:06 +02:00
|
|
|
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:17:01 +02:00
|
|
|
#[inline(always)]
|
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 {
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 18:11:06 +02:00
|
|
|
fn outer_mul(self, t: T) -> Self {
|
|
|
|
self * t
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 18:11:06 +02:00
|
|
|
fn outer_div(self, t: T) -> Self {
|
|
|
|
self / t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:12:04 +02:00
|
|
|
impl<T> Interpolate<T> for Quaternion<T>
|
|
|
|
where Self: InnerSpace<Scalar = T>, T: Additive + BaseFloat + One {
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 18:11:06 +02:00
|
|
|
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:17:01 +02:00
|
|
|
#[inline(always)]
|
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)
|
|
|
|
}
|
|
|
|
}
|