splines/src/cgmath.rs

65 lines
1.5 KiB
Rust
Raw Normal View History

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-21 18:11:06 +02:00
use crate::interpolate::{Additive, Interpolate, Linear, One, cubic_hermite_def};
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 {
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 {
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-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)
}
}