fixed formatting to match project conventions. changed Matrix::zip_map to Vector::zip_map for clarity

This commit is contained in:
nsmryan 2018-10-03 22:35:40 -04:00
parent 18345bf9a0
commit e8efebef7c
2 changed files with 32 additions and 44 deletions

View File

@ -398,66 +398,54 @@ impl Interpolate for Quaternion<f32> {
impl<N: Scalar, D: DimName> Interpolate for na::Point<N, D>
where DefaultAllocator: Allocator<N, D>,
<DefaultAllocator as Allocator<N, D>>::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<f32>
{
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<f32> {
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<f32>
{
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<f32> {
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<f32>
{
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<f32> {
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<f32>
{
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<f32> {
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<f32>
{
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<f32> {
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<f32>
{
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<f32> {
fn lerp(a: Self, b: Self, t: f32) -> Self {
na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
}
}

View File

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