added basic tests for nalgebra, and cleaned up some unused imports
This commit is contained in:
parent
b795267632
commit
15e0efa9c0
24
src/lib.rs
24
src/lib.rs
@ -110,11 +110,8 @@
|
|||||||
#[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 nalgebra as na;
|
#[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::allocator::Allocator;
|
||||||
#[cfg(feature = "impl-nalgebra")] use nalgebra::core::{DimName, DefaultAllocator, Scalar};
|
#[cfg(feature = "impl-nalgebra")] use nalgebra::core::{DimName, DefaultAllocator, Scalar};
|
||||||
#[cfg(feature = "impl-nalgebra")] use nalgebra::storage::Storage;
|
|
||||||
#[cfg(feature = "impl-nalgebra")] use generic_array::ArrayLength;
|
|
||||||
|
|
||||||
#[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;
|
||||||
@ -404,12 +401,11 @@ impl<N : Scalar, D : DimName> Interpolate for na::Point<N, D>
|
|||||||
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
|
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
|
||||||
N : Interpolate,
|
N : Interpolate,
|
||||||
{
|
{
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
let lerp = |c1 : N, c2 : N| { Interpolate::lerp(c1, c2, t) };
|
let lerp = |c1 : N, c2 : N| { Interpolate::lerp(c1, c2, t) };
|
||||||
let coords = Matrix::zip_map(&a.coords, &b.coords, lerp);
|
let coords = na::Matrix::zip_map(&a.coords, &b.coords, lerp);
|
||||||
na::Point::from_coordinates(coords)
|
na::Point::from_coordinates(coords)
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
@ -421,11 +417,11 @@ impl<R, C> Interpolate for na::Matrix<f32, R, C, <DefaultAllocator as Allocator<
|
|||||||
<<R as na::DimName>::Value as Mul<<C as na::DimName>::Value>>::Output : generic_array::ArrayLength<f32>,
|
<<R as na::DimName>::Value as Mul<<C as na::DimName>::Value>>::Output : generic_array::ArrayLength<f32>,
|
||||||
<<<R as na::DimName>::Value as Mul<<C as na::DimName>::Value>>::Output as generic_array::ArrayLength<f32>>::ArrayType : Copy,
|
<<<R as na::DimName>::Value as Mul<<C as na::DimName>::Value>>::Output as generic_array::ArrayLength<f32>>::ArrayType : Copy,
|
||||||
{
|
{
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self
|
fn lerp(a: Self, b: Self, t: f32) -> Self
|
||||||
{
|
{
|
||||||
let lerp = |c1 : f32, c2 : f32| Interpolate::lerp(c1, c2, t);
|
let lerp = |c1 : f32, c2 : f32| Interpolate::lerp(c1, c2, t);
|
||||||
Matrix::zip_map(&a, &b, lerp)
|
na::Matrix::zip_map(&a, &b, lerp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default implementation of Interpolate::cubic_hermit.
|
// Default implementation of Interpolate::cubic_hermit.
|
||||||
|
30
tests/mod.rs
30
tests/mod.rs
@ -1,6 +1,9 @@
|
|||||||
extern crate splines;
|
extern crate splines;
|
||||||
|
#[cfg(feature = "impl-nalgebra")] extern crate nalgebra;
|
||||||
|
|
||||||
|
use splines::{Interpolation, Key, Spline, Interpolate};
|
||||||
|
#[cfg(feature = "impl-nalgebra")] use nalgebra as na;
|
||||||
|
|
||||||
use splines::{Interpolation, Key, Spline};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn step_interpolation_0() {
|
fn step_interpolation_0() {
|
||||||
@ -128,3 +131,28 @@ fn several_interpolations_several_keys() {
|
|||||||
assert_eq!(spline.sample(10.), Some(2.));
|
assert_eq!(spline.sample(10.), Some(2.));
|
||||||
assert_eq!(spline.clamped_sample(11.), 4.);
|
assert_eq!(spline.clamped_sample(11.), 4.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
|
fn nalgebra_point_interpolation() {
|
||||||
|
let start : na::Point2<f32> = na::Point2::new(0.0, 0.0);
|
||||||
|
let mid : na::Point2<f32> = na::Point2::new(0.5, 0.5);
|
||||||
|
let end : na::Point2<f32> = na::Point2::new(1.0, 1.0);
|
||||||
|
|
||||||
|
assert_eq!(Interpolate::lerp(start, end, 0.0), start);
|
||||||
|
assert_eq!(Interpolate::lerp(start, end, 1.0), end);
|
||||||
|
assert_eq!(Interpolate::lerp(start, end, 0.5), mid);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
|
fn nalgebra_vector_interpolation() {
|
||||||
|
let start : na::Vector2<f32> = na::Vector2::new(0.0, 0.0);
|
||||||
|
let mid : na::Vector2<f32> = na::Vector2::new(0.5, 0.5);
|
||||||
|
let end : na::Vector2<f32> = na::Vector2::new(1.0, 1.0);
|
||||||
|
|
||||||
|
assert_eq!(Interpolate::lerp(start, end, 0.0), start);
|
||||||
|
assert_eq!(Interpolate::lerp(start, end, 1.0), end);
|
||||||
|
assert_eq!(Interpolate::lerp(start, end, 0.5), mid);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user