2019-04-25 10:45:49 +02:00
|
|
|
use nalgebra::{Scalar, Vector, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6};
|
2019-04-21 17:54:24 +02:00
|
|
|
use num_traits as nt;
|
2020-04-06 12:04:08 +02:00
|
|
|
use simba::scalar::{ClosedAdd, ClosedDiv, ClosedMul, ClosedSub};
|
2019-04-21 17:54:24 +02:00
|
|
|
use std::ops::Mul;
|
2019-04-19 13:39:37 +02:00
|
|
|
|
2019-09-23 20:56:56 +02:00
|
|
|
use crate::interpolate::{
|
2020-03-19 01:22:26 +01:00
|
|
|
cubic_bezier_def, cubic_hermite_def, quadratic_bezier_def, Additive, Interpolate, Linear, One,
|
2019-09-23 20:56:56 +02:00
|
|
|
};
|
2019-04-19 13:39:37 +02:00
|
|
|
|
2019-04-21 17:54:24 +02:00
|
|
|
macro_rules! impl_interpolate_vector {
|
2019-04-19 13:39:37 +02:00
|
|
|
($($t:tt)*) => {
|
2019-04-21 17:54:24 +02:00
|
|
|
// implement Linear
|
2020-03-17 11:06:41 +01:00
|
|
|
impl<T> Linear<T> for $($t)*<T>
|
|
|
|
where T: Scalar +
|
|
|
|
Copy +
|
|
|
|
ClosedAdd +
|
|
|
|
ClosedSub +
|
|
|
|
ClosedMul +
|
|
|
|
ClosedDiv {
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 17:54:24 +02:00
|
|
|
fn outer_mul(self, t: T) -> Self {
|
|
|
|
self * t
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 17:54:24 +02:00
|
|
|
fn outer_div(self, t: T) -> Self {
|
|
|
|
self / t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, V> Interpolate<T> for $($t)*<V>
|
|
|
|
where Self: Linear<T>,
|
|
|
|
T: Additive + One + Mul<T, Output = T>,
|
|
|
|
V: nt::One +
|
|
|
|
nt::Zero +
|
|
|
|
Additive +
|
|
|
|
Scalar +
|
|
|
|
ClosedAdd +
|
|
|
|
ClosedMul +
|
|
|
|
ClosedSub +
|
|
|
|
Interpolate<T> {
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-19 13:39:37 +02:00
|
|
|
fn lerp(a: Self, b: Self, t: T) -> Self {
|
2019-04-21 17:54:24 +02:00
|
|
|
Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:17:01 +02:00
|
|
|
#[inline(always)]
|
2019-04-21 17:54:24 +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-19 13:39:37 +02:00
|
|
|
}
|
2019-09-23 20:56:56 +02:00
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn quadratic_bezier(a: Self, u: Self, b: Self, t: T) -> Self {
|
|
|
|
quadratic_bezier_def(a, u, b, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn cubic_bezier(a: Self, u: Self, v: Self, b: Self, t: T) -> Self {
|
|
|
|
cubic_bezier_def(a, u, v, b, t)
|
|
|
|
}
|
2019-04-19 13:39:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-21 17:54:24 +02:00
|
|
|
impl_interpolate_vector!(Vector1);
|
|
|
|
impl_interpolate_vector!(Vector2);
|
|
|
|
impl_interpolate_vector!(Vector3);
|
|
|
|
impl_interpolate_vector!(Vector4);
|
|
|
|
impl_interpolate_vector!(Vector5);
|
|
|
|
impl_interpolate_vector!(Vector6);
|