From e8efebef7c2fcc5cfb6874564fa884d0cc05e563 Mon Sep 17 00:00:00 2001 From: nsmryan Date: Wed, 3 Oct 2018 22:35:40 -0400 Subject: [PATCH] fixed formatting to match project conventions. changed Matrix::zip_map to Vector::zip_map for clarity --- src/lib.rs | 60 +++++++++++++++++++++------------------------------- tests/mod.rs | 16 +++++++------- 2 files changed, 32 insertions(+), 44 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 27c0240..802165a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -395,69 +395,57 @@ impl Interpolate for Quaternion { } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for na::Point - where DefaultAllocator : Allocator, +impl Interpolate for na::Point + where DefaultAllocator: Allocator, >::Buffer: Copy, - N : Interpolate, -{ + N: Interpolate { fn lerp(a: Self, b: Self, t: f32) -> Self { - let lerp = |c1 : N, c2 : N| { Interpolate::lerp(c1, c2, t) }; - let coords = na::Matrix::zip_map(&a.coords, &b.coords, lerp); + // The 'coords' of a point is just a vector, so we can interpolate component-wise + // over these vectors. + let coords = na::Vector::zip_map(&a.coords, &b.coords, |c1, c2| Interpolate::lerp(c1, c2, t)); na::Point::from_coordinates(coords) } } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for na::Vector1 -{ - fn lerp(a: Self, b: Self, t: f32) -> Self - { - na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) +impl Interpolate for na::Vector1 { + fn lerp(a: Self, b: Self, t: f32) -> Self { + na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) } } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for na::Vector2 -{ - fn lerp(a: Self, b: Self, t: f32) -> Self - { - na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) +impl Interpolate for na::Vector2 { + fn lerp(a: Self, b: Self, t: f32) -> Self { + na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) } } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for na::Vector3 -{ - fn lerp(a: Self, b: Self, t: f32) -> Self - { - na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) +impl Interpolate for na::Vector3 { + fn lerp(a: Self, b: Self, t: f32) -> Self { + na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) } } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for na::Vector4 -{ - fn lerp(a: Self, b: Self, t: f32) -> Self - { - na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) +impl Interpolate for na::Vector4 { + fn lerp(a: Self, b: Self, t: f32) -> Self { + na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) } } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for na::Vector5 -{ - fn lerp(a: Self, b: Self, t: f32) -> Self - { - na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) +impl Interpolate for na::Vector5 { + fn lerp(a: Self, b: Self, t: f32) -> Self { + na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) } } #[cfg(feature = "impl-nalgebra")] -impl Interpolate for na::Vector6 -{ - fn lerp(a: Self, b: Self, t: f32) -> Self - { - na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) +impl Interpolate for na::Vector6 { + fn lerp(a: Self, b: Self, t: f32) -> Self { + na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t)) } } diff --git a/tests/mod.rs b/tests/mod.rs index 39061ea..e171ee4 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -132,24 +132,24 @@ fn several_interpolations_several_keys() { assert_eq!(spline.clamped_sample(11.), 4.); } -#[test] #[cfg(feature = "impl-nalgebra")] +#[test] fn nalgebra_point_interpolation() { - let start : na::Point2 = na::Point2::new(0.0, 0.0); - let mid : na::Point2 = na::Point2::new(0.5, 0.5); - let end : na::Point2 = na::Point2::new(1.0, 1.0); + 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); } -#[test] #[cfg(feature = "impl-nalgebra")] +#[test] fn nalgebra_vector_interpolation() { - let start : na::Vector2 = na::Vector2::new(0.0, 0.0); - let mid : na::Vector2 = na::Vector2::new(0.5, 0.5); - let end : na::Vector2 = na::Vector2::new(1.0, 1.0); + 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);