Add OPoint::lerp

This commit is contained in:
+merlan #flirora 2023-06-03 03:55:36 -04:00
parent 1a271ac541
commit a1fcd1cb73
1 changed files with 26 additions and 1 deletions

View File

@ -1,6 +1,7 @@
use crate::storage::Storage; use crate::storage::Storage;
use crate::{ use crate::{
Allocator, DefaultAllocator, Dim, OVector, One, RealField, Scalar, Unit, Vector, Zero, Allocator, DefaultAllocator, Dim, DimName, OPoint, OVector, One, RealField, Scalar, Unit,
Vector, Zero,
}; };
use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub}; use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub};
@ -58,6 +59,30 @@ impl<T: Scalar + Zero + One + ClosedAdd + ClosedSub + ClosedMul, D: Dim, S: Stor
} }
} }
impl<T: Scalar + Zero + One + ClosedAdd + ClosedSub + ClosedMul, D: DimName> OPoint<T, D>
where
DefaultAllocator: Allocator<T, D>,
{
/// Returns `self * (1.0 - t) + rhs.coords * t`, i.e., the linear blend of the points x and y using the scalar value a.
///
/// The value for a is not restricted to the range `[0, 1]`.
///
/// # Examples:
///
/// ```
/// # use nalgebra::Point3;
/// let x = Point3::new(1.0, 2.0, 3.0);
/// let y = Point3::new(10.0, 20.0, 30.0);
/// assert_eq!(x.lerp(&y, 0.1), Point3::new(1.9, 3.8, 5.7));
/// ```
#[must_use]
pub fn lerp(&self, rhs: &OPoint<T, D>, t: T) -> OPoint<T, D> {
OPoint {
coords: self.coords.lerp(&rhs.coords, t),
}
}
}
/// # Interpolation between two unit vectors /// # Interpolation between two unit vectors
impl<T: RealField, D: Dim, S: Storage<T, D>> Unit<Vector<T, D, S>> { impl<T: RealField, D: Dim, S: Storage<T, D>> Unit<Vector<T, D, S>> {
/// Computes the spherical linear interpolation between two unit vectors. /// Computes the spherical linear interpolation between two unit vectors.