From 427895ab106dd3f35175f64a1ec1b928f08ff8db Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Fri, 19 Apr 2019 15:45:27 +0200 Subject: [PATCH] The cubic_hermite_def function is a bit fucked as impossible to use. --- Cargo.toml | 2 ++ src/cgmath.rs | 26 ++++++++++++++++++++++++++ src/lib.rs | 4 ++++ 3 files changed, 32 insertions(+) create mode 100644 src/cgmath.rs diff --git a/Cargo.toml b/Cargo.toml index f6d378b..c5e6533 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,9 +23,11 @@ maintenance = { status = "actively-developed" } default = ["std"] serialization = ["serde", "serde_derive"] std = ["num-traits/std"] +impl-cgmath = ["cgmath"] impl-nalgebra = ["nalgebra"] [dependencies] +cgmath = { version = "0.17", optional = true } nalgebra = { version = ">=0.14, <0.19", optional = true } num-traits = { version = "0.2", default-features = false } serde = { version = "1", optional = true } diff --git a/src/cgmath.rs b/src/cgmath.rs new file mode 100644 index 0000000..9cdd459 --- /dev/null +++ b/src/cgmath.rs @@ -0,0 +1,26 @@ +use cgmath::{BaseNum, InnerSpace, Quaternion, VectorSpace, Vector2, Vector3, Vector4}; +use num_traits::Float; + +use crate::interpolate::{Interpolate, cubic_hermite_def}; + +macro_rules! impl_interpolate_vec { + ($t:ty, $($q:tt)*) => { + impl Interpolate<$t> for $($q)*<$t> { + fn lerp(a: Self, b: Self, t: $t) -> Self { + a.lerp(b, t) + } + + 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) + } + } + } +} + +impl_interpolate_vec!(f32, Vector2); + +//impl Interpolate for Quaternion { +// fn lerp(a: Self, b: Self, t: f32) -> Self { +// a.nlerp(b, t) +// } +//} diff --git a/src/lib.rs b/src/lib.rs index edd3a4d..15031c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,6 +81,9 @@ //! + This feature implements both the `Serialize` and `Deserialize` traits from `serde` for all //! types exported by this crate. //! + Enable with the `"serialization"` feature. +//! - **[cgmath](https://crates.io/crates/cgmath) implementors.** +//! + Adds some useful implementations of `Interpolate` for some cgmath types. +//! + Enable with the `"impl-cgmath"` feature. //! - **[nalgebra](https://crates.io/crates/nalgebra) implementors.** //! + Adds some useful implementations of `Interpolate` for some nalgebra types. //! + Enable with the `"impl-nalgebra"` feature. @@ -94,6 +97,7 @@ #![cfg_attr(not(feature = "std"), feature(alloc))] #![cfg_attr(not(feature = "std"), feature(core_intrinsics))] +#[cfg(feature = "impl-cgmath")] mod cgmath; pub mod interpolate; pub mod interpolation; pub mod iter;