fixed formatting to match project conventions. changed Matrix::zip_map to Vector::zip_map for clarity
This commit is contained in:
parent
18345bf9a0
commit
e8efebef7c
56
src/lib.rs
56
src/lib.rs
@ -398,66 +398,54 @@ impl Interpolate for Quaternion<f32> {
|
|||||||
impl<N: Scalar, D: DimName> Interpolate for na::Point<N, D>
|
impl<N: Scalar, D: DimName> Interpolate for na::Point<N, D>
|
||||||
where DefaultAllocator: Allocator<N, D>,
|
where DefaultAllocator: Allocator<N, D>,
|
||||||
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
|
<DefaultAllocator as Allocator<N, D>>::Buffer: Copy,
|
||||||
N : Interpolate,
|
N: Interpolate {
|
||||||
{
|
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
let lerp = |c1 : N, c2 : N| { Interpolate::lerp(c1, c2, t) };
|
// The 'coords' of a point is just a vector, so we can interpolate component-wise
|
||||||
let coords = na::Matrix::zip_map(&a.coords, &b.coords, lerp);
|
// 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)
|
na::Point::from_coordinates(coords)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
impl Interpolate for na::Vector1<f32>
|
impl Interpolate for na::Vector1<f32> {
|
||||||
{
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self
|
na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
||||||
{
|
|
||||||
na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
impl Interpolate for na::Vector2<f32>
|
impl Interpolate for na::Vector2<f32> {
|
||||||
{
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self
|
na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
||||||
{
|
|
||||||
na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
impl Interpolate for na::Vector3<f32>
|
impl Interpolate for na::Vector3<f32> {
|
||||||
{
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self
|
na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
||||||
{
|
|
||||||
na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
impl Interpolate for na::Vector4<f32>
|
impl Interpolate for na::Vector4<f32> {
|
||||||
{
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self
|
na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
||||||
{
|
|
||||||
na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
impl Interpolate for na::Vector5<f32>
|
impl Interpolate for na::Vector5<f32> {
|
||||||
{
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self
|
na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
||||||
{
|
|
||||||
na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
impl Interpolate for na::Vector6<f32>
|
impl Interpolate for na::Vector6<f32> {
|
||||||
{
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self
|
na::Vector::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
||||||
{
|
|
||||||
na::Matrix::zip_map(&a, &b, |c1, c2| Interpolate::lerp(c1, c2, t))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
tests/mod.rs
16
tests/mod.rs
@ -132,24 +132,24 @@ fn several_interpolations_several_keys() {
|
|||||||
assert_eq!(spline.clamped_sample(11.), 4.);
|
assert_eq!(spline.clamped_sample(11.), 4.);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
|
#[test]
|
||||||
fn nalgebra_point_interpolation() {
|
fn nalgebra_point_interpolation() {
|
||||||
let start : na::Point2<f32> = na::Point2::new(0.0, 0.0);
|
let start = na::Point2::new(0.0, 0.0);
|
||||||
let mid : na::Point2<f32> = na::Point2::new(0.5, 0.5);
|
let mid = na::Point2::new(0.5, 0.5);
|
||||||
let end : na::Point2<f32> = na::Point2::new(1.0, 1.0);
|
let end = na::Point2::new(1.0, 1.0);
|
||||||
|
|
||||||
assert_eq!(Interpolate::lerp(start, end, 0.0), start);
|
assert_eq!(Interpolate::lerp(start, end, 0.0), start);
|
||||||
assert_eq!(Interpolate::lerp(start, end, 1.0), end);
|
assert_eq!(Interpolate::lerp(start, end, 1.0), end);
|
||||||
assert_eq!(Interpolate::lerp(start, end, 0.5), mid);
|
assert_eq!(Interpolate::lerp(start, end, 0.5), mid);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[cfg(feature = "impl-nalgebra")]
|
#[cfg(feature = "impl-nalgebra")]
|
||||||
|
#[test]
|
||||||
fn nalgebra_vector_interpolation() {
|
fn nalgebra_vector_interpolation() {
|
||||||
let start : na::Vector2<f32> = na::Vector2::new(0.0, 0.0);
|
let start = na::Vector2::new(0.0, 0.0);
|
||||||
let mid : na::Vector2<f32> = na::Vector2::new(0.5, 0.5);
|
let mid = na::Vector2::new(0.5, 0.5);
|
||||||
let end : na::Vector2<f32> = na::Vector2::new(1.0, 1.0);
|
let end = na::Vector2::new(1.0, 1.0);
|
||||||
|
|
||||||
assert_eq!(Interpolate::lerp(start, end, 0.0), start);
|
assert_eq!(Interpolate::lerp(start, end, 0.0), start);
|
||||||
assert_eq!(Interpolate::lerp(start, end, 1.0), end);
|
assert_eq!(Interpolate::lerp(start, end, 1.0), end);
|
||||||
|
Loading…
Reference in New Issue
Block a user