diff --git a/src/base/matrix.rs b/src/base/matrix.rs index a52b18e4..91e47624 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -1,4 +1,4 @@ -use num::Zero; +use num::{One, Zero}; use num_complex::Complex; #[cfg(feature = "abomonation-serialize")] use std::io::{Result as IOResult, Write}; @@ -16,7 +16,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; -use alga::general::{Real, Ring}; +use alga::general::{ClosedAdd, ClosedMul, ClosedSub, Real, Ring}; use base::allocator::{Allocator, SameShapeAllocator, SameShapeC, SameShapeR}; use base::constraint::{DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; @@ -1307,6 +1307,29 @@ impl> Matrix { } } +impl> + Vector +{ + /// Returns `self * (1.0 - t) + rhs * t`, i.e., the linear blend of the vectors x and y using the scalar value a. + /// + /// The value for a is not restricted to the range `[0, 1]`. + /// + /// # Examples: + /// + /// ``` + /// # use nalgebra::Vector3; + /// let x = Vector3::new(1.0, 2.0, 3.0); + /// let y = Vector3::new(10.0, 20.0, 30.0); + /// assert_eq!(x.lerp(&y, 0.1), Vector3::new(1.9, 3.8, 5.7)); + /// ``` + pub fn lerp>(&self, rhs: &Vector, t: N) -> VectorN + where DefaultAllocator: Allocator { + let mut res = self.clone_owned(); + res.axpy(t, rhs, N::one() - t); + res + } +} + impl> Unit> { /// Computes the spherical linear interpolation between two unit vectors. pub fn slerp>(