Add impl Interpolate for some cgmath types.
This commit is contained in:
parent
fb22023702
commit
fbeade556c
@ -18,3 +18,4 @@ is-it-maintained-open-issues = { repository = "phaazon/spline" }
|
||||
maintenance = { status = "actively-developed" }
|
||||
|
||||
[dependencies]
|
||||
cgmath = "0.16"
|
||||
|
39
src/lib.rs
39
src/lib.rs
@ -64,6 +64,9 @@
|
||||
//!
|
||||
//! 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::f32::consts;
|
||||
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.
|
||||
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> {
|
||||
|
Loading…
Reference in New Issue
Block a user