successfully implemented Interpolate for all Point types. Vectors require an implementation for Matrix, which is proving trickier
This commit is contained in:
parent
204b22aa0b
commit
2912848397
@ -25,7 +25,7 @@ impl-cgmath = ["cgmath"]
|
|||||||
impl-nalgebra = ["nalgebra"]
|
impl-nalgebra = ["nalgebra"]
|
||||||
|
|
||||||
[dependencies.nalgebra]
|
[dependencies.nalgebra]
|
||||||
version = "0.16"
|
version = "0.14"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies.cgmath]
|
[dependencies.cgmath]
|
||||||
|
39
src/lib.rs
39
src/lib.rs
@ -83,10 +83,13 @@
|
|||||||
//! - **[cgmath](https://crates.io/crates/cgmath) implementors.**
|
//! - **[cgmath](https://crates.io/crates/cgmath) implementors.**
|
||||||
//! + Adds some usefull implementations of `Interpolate` for some cgmath types.
|
//! + Adds some usefull implementations of `Interpolate` for some cgmath types.
|
||||||
//! + Enable with the `"impl-cgmath"` feature.
|
//! + 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.
|
//! + 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.
|
//! + 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.
|
//! + Enable explicitly with the `"std"` feataure.
|
||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![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-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::cmp::Ordering;
|
||||||
#[cfg(feature = "std")] use std::f32::consts;
|
#[cfg(feature = "std")] use std::f32::consts;
|
||||||
@ -390,16 +397,32 @@ impl Interpolate for Quaternion<f32> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
impl<T : Interpolate > Interpolate for Point<T> {
|
impl<N : Scalar, D : DimName> Interpolate for na::Point<N, D>
|
||||||
|
where DefaultAllocator : Allocator<N, D>,
|
||||||
|
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
|
||||||
|
N : Interpolate,
|
||||||
|
{
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
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")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
impl<T : Interpolate > Interpolate for Vector<T> {
|
impl<N, R, C> Interpolate for na::Matrix<N, R, C, <DefaultAllocator as Allocator<N, R, C>>::Buffer>
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
where N : Interpolate,
|
||||||
a.lerp(b, t)
|
N : Scalar,
|
||||||
|
R : DimName,
|
||||||
|
C : DimName,
|
||||||
|
<R as na::DimName>::Value : Mul<<C as na::DimName>::Value>,
|
||||||
|
<C as na::DimName>::Value : Mul<<R as na::DimName>::Value>,
|
||||||
|
<<R as na::DimName>::Value as Mul<<C as na::DimName>::Value>>::Output : generic_array::ArrayLengh<N>
|
||||||
|
{
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user