Add impl Interpolate for some cgmath types.

This commit is contained in:
Dimitri Sabadie 2018-08-05 17:23:30 +02:00
parent fb22023702
commit fbeade556c
No known key found for this signature in database
GPG Key ID: DE58C386A8DB2883
2 changed files with 40 additions and 0 deletions

View File

@ -18,3 +18,4 @@ is-it-maintained-open-issues = { repository = "phaazon/spline" }
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }
[dependencies] [dependencies]
cgmath = "0.16"

View File

@ -64,6 +64,9 @@
//! //!
//! Feel free to have a look at the rest of the documentation for advanced usage. //! Feel free to have a look at the rest of the documentation for advanced usage.
extern crate cgmath;
use cgmath::{InnerSpace, Quaternion, Vector2, Vector3, Vector4};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::f32::consts; use std::f32::consts;
use std::ops::{Add, Div, Mul, Sub}; use std::ops::{Add, Div, Mul, Sub};
@ -285,6 +288,42 @@ impl Interpolate for f32 {
} }
} }
impl Interpolate for Vector2<f32> {
fn lerp(a: Self, b: Self, t: f32) -> Self {
a.lerp(b, t)
}
fn cubic_hermite(x: (Self, f32), a: (Self, f32), b: (Self, f32), y: (Self, f32), t: f32) -> Self {
cubic_hermite(x, a, b, y, t)
}
}
impl Interpolate for Vector3<f32> {
fn lerp(a: Self, b: Self, t: f32) -> Self {
a.lerp(b, t)
}
fn cubic_hermite(x: (Self, f32), a: (Self, f32), b: (Self, f32), y: (Self, f32), t: f32) -> Self {
cubic_hermite(x, a, b, y, t)
}
}
impl Interpolate for Vector4<f32> {
fn lerp(a: Self, b: Self, t: f32) -> Self {
a.lerp(b, t)
}
fn cubic_hermite(x: (Self, f32), a: (Self, f32), b: (Self, f32), y: (Self, f32), t: f32) -> Self {
cubic_hermite(x, a, b, y, t)
}
}
impl Interpolate for Quaternion<f32> {
fn lerp(a: Self, b: Self, t: f32) -> Self {
a.nlerp(b, t)
}
}
// Default implementation of Interpolate::cubic_hermit. // Default implementation of Interpolate::cubic_hermit.
pub(crate) fn cubic_hermite<T>(x: (T, f32), a: (T, f32), b: (T, f32), y: (T, f32), t: f32) -> T pub(crate) fn cubic_hermite<T>(x: (T, f32), a: (T, f32), b: (T, f32), y: (T, f32), t: f32) -> T
where T: Copy + Add<Output = T> + Sub<Output = T> + Mul<f32, Output = T> + Div<f32, Output = T> { where T: Copy + Add<Output = T> + Sub<Output = T> + Mul<f32, Output = T> + Div<f32, Output = T> {