Add support for nalgebra along with some tests.

Feature-gated with impl-nalgebra.
This commit is contained in:
nsmryan
2018-09-30 10:11:35 -04:00
committed by Dimitri Sabadie
parent 766066d9ed
commit 77ccf0a47b
3 changed files with 99 additions and 0 deletions

View File

@ -1,4 +1,8 @@
extern crate splines;
#[cfg(feature = "impl-nalgebra")] extern crate nalgebra;
#[cfg(feature = "impl-nalgebra")] use nalgebra as na;
#[cfg(feature = "impl-nalgebra")] use splines::Interpolate;
use splines::{Interpolation, Key, Spline};
@ -128,3 +132,28 @@ fn several_interpolations_several_keys() {
assert_eq!(spline.sample(10.), Some(2.));
assert_eq!(spline.clamped_sample(11.), 4.);
}
#[cfg(feature = "impl-nalgebra")]
#[test]
fn nalgebra_point_interpolation() {
let start = na::Point2::new(0.0, 0.0);
let mid = na::Point2::new(0.5, 0.5);
let end = 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);
}
#[cfg(feature = "impl-nalgebra")]
#[test]
fn nalgebra_vector_interpolation() {
let start = na::Vector2::new(0.0, 0.0);
let mid = na::Vector2::new(0.5, 0.5);
let end = 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);
}