Skip to content

Commit

Permalink
Merge pull request #1243 from bluebear94/mf/point-lerp
Browse files Browse the repository at this point in the history
Add OPoint::lerp
  • Loading branch information
sebcrozet committed Jul 8, 2023
2 parents bea7f9d + 1e38e6f commit 17f5ec1
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/geometry/point.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use approx::{AbsDiffEq, RelativeEq, UlpsEq};
use num::One;
use num::{One, Zero};
use std::cmp::Ordering;
use std::fmt;
use std::hash;
Expand All @@ -13,6 +13,7 @@ use crate::base::allocator::Allocator;
use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1};
use crate::base::iter::{MatrixIter, MatrixIterMut};
use crate::base::{Const, DefaultAllocator, OVector, Scalar};
use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub};
use std::mem::MaybeUninit;

/// A point in an euclidean space.
Expand Down Expand Up @@ -221,6 +222,31 @@ where
unsafe { res.assume_init() }
}

/// Linear interpolation between two points.
///
/// Returns `self * (1.0 - t) + rhs.coords * t`, i.e., the linear blend of the points
/// `self` and `rhs` using the scalar value `t`.
///
/// The value for a is not restricted to the range `[0, 1]`.
///
/// # Examples:
///
/// ```
/// # use nalgebra::Point3;
/// let a = Point3::new(1.0, 2.0, 3.0);
/// let b = Point3::new(10.0, 20.0, 30.0);
/// assert_eq!(a.lerp(&b, 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>
where
T: Scalar + Zero + One + ClosedAdd + ClosedSub + ClosedMul,
{
OPoint {
coords: self.coords.lerp(&rhs.coords, t),
}
}

/// Creates a new point with the given coordinates.
#[deprecated(note = "Use Point::from(vector) instead.")]
#[inline]
Expand Down

0 comments on commit 17f5ec1

Please sign in to comment.