diff --git a/Cargo.toml b/Cargo.toml index 956a0cf..ff3517d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ impl-cgmath = ["cgmath"] impl-nalgebra = ["nalgebra"] [dependencies.nalgebra] -version = "0.16" +version = "0.14" optional = true [dependencies.cgmath] diff --git a/src/lib.rs b/src/lib.rs index 138cfc8..e7cb84b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,10 +83,13 @@ //! - **[cgmath](https://crates.io/crates/cgmath) implementors.** //! + Adds some usefull implementations of `Interpolate` for some cgmath types. //! + Enable with the `"impl-cgmath"` feature. -//! - **Standard library / no stdandard library.** +//! - **[nalgebra](https://crates.io/crates/nalgebra) implementors.** +//! + Adds some usefull implementations of `Interpolate` for some nalgebra types. +//! + Enable with the `"impl-nalgebra"` feature. +//! - **Standard library / no standard library.** //! + It’s possible to compile against the standard library or go on your own without it. //! + Compiling with the standard library is enabled by default. -//! + Use `defaut-features = []` in your `Cargo.toml` to disable. +//! + Use `default-features = []` in your `Cargo.toml` to disable. //! + Enable explicitly with the `"std"` feataure. #![cfg_attr(not(feature = "std"), no_std)] @@ -105,7 +108,11 @@ #[cfg(feature = "impl-cgmath")] use cgmath::{InnerSpace, Quaternion, Vector2, Vector3, Vector4}; -#[cfg(feature = "impl-nalgebra")] use nalgera::{Point, Vector}; +#[cfg(feature = "impl-nalgebra")] use nalgebra as na; +#[cfg(feature = "impl-nalgebra")] use nalgebra::Matrix; +#[cfg(feature = "impl-nalgebra")] use nalgebra::core::allocator::Allocator; +#[cfg(feature = "impl-nalgebra")] use nalgebra::core::{DimName, DefaultAllocator, Scalar}; +#[cfg(feature = "impl-nalgebra")] use nalgebra::storage::Storage; #[cfg(feature = "std")] use std::cmp::Ordering; #[cfg(feature = "std")] use std::f32::consts; @@ -390,16 +397,32 @@ impl Interpolate for Quaternion { } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for Point { +impl Interpolate for na::Point + where DefaultAllocator : Allocator, + >::Buffer: Copy, + N : Interpolate, +{ fn lerp(a: Self, b: Self, t: f32) -> Self { - a.lerp(b, t) + let lerp = |c1 : N, c2 : N| { Interpolate::lerp(c1, c2, t) }; + let coords = Matrix::zip_map(&a.coords, &b.coords, lerp); + na::Point::from_coordinates(coords) } } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for Vector { - fn lerp(a: Self, b: Self, t: f32) -> Self { - a.lerp(b, t) +impl Interpolate for na::Matrix>::Buffer> + where N : Interpolate, + N : Scalar, + R : DimName, + C : DimName, + ::Value : Mul<::Value>, + ::Value : Mul<::Value>, + <::Value as Mul<::Value>>::Output : generic_array::ArrayLengh +{ + fn lerp(a: Self, b: Self, t: f32) -> Self + { + let lerp = |c1 : N, c2 : N| Interpolate::lerp(c1, c2, t); + Matrix::zip_map(&a, &b, lerp) } }