diff --git a/Cargo.toml b/Cargo.toml index 8db2563..f00ef3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ is-it-maintained-open-issues = { repository = "phaazon/spline" } maintenance = { status = "actively-developed" } [dependencies] +cgmath = "0.16" diff --git a/src/lib.rs b/src/lib.rs index 6c19754..dfe1110 100644 --- a/src/lib.rs +++ b/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 { + 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 { + 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 { + 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 { + fn lerp(a: Self, b: Self, t: f32) -> Self { + a.nlerp(b, t) + } +} + // Default implementation of Interpolate::cubic_hermit. pub(crate) fn cubic_hermite(x: (T, f32), a: (T, f32), b: (T, f32), y: (T, f32), t: f32) -> T where T: Copy + Add + Sub + Mul + Div {