added basic tests for nalgebra, and cleaned up some unused imports
This commit is contained in:
parent
b795267632
commit
15e0efa9c0
@ -110,11 +110,8 @@
|
||||
#[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::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 = "impl-nalgebra")] use generic_array::ArrayLength;
|
||||
|
||||
#[cfg(feature = "std")] use std::cmp::Ordering;
|
||||
#[cfg(feature = "std")] use std::f32::consts;
|
||||
@ -406,9 +403,8 @@ impl<N : Scalar, D : DimName> Interpolate for na::Point<N, D>
|
||||
{
|
||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -424,7 +420,7 @@ impl<R, C> Interpolate for na::Matrix<f32, R, C, <DefaultAllocator as Allocator<
|
||||
fn lerp(a: Self, b: Self, t: f32) -> Self
|
||||
{
|
||||
let lerp = |c1 : f32, c2 : f32| Interpolate::lerp(c1, c2, t);
|
||||
Matrix::zip_map(&a, &b, lerp)
|
||||
na::Matrix::zip_map(&a, &b, lerp)
|
||||
}
|
||||
}
|
||||
|
||||
|
30
tests/mod.rs
30
tests/mod.rs
@ -1,6 +1,9 @@
|
||||
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]
|
||||
fn step_interpolation_0() {
|
||||
@ -128,3 +131,28 @@ fn several_interpolations_several_keys() {
|
||||
assert_eq!(spline.sample(10.), Some(2.));
|
||||
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