added basic tests for nalgebra, and cleaned up some unused imports

This commit is contained in:
nsmryan
2018-09-30 11:05:54 -04:00
parent b795267632
commit 15e0efa9c0
2 changed files with 39 additions and 15 deletions

View File

@ -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);
}