Add magnitude synonym functions for ease of use

This commit is contained in:
Jacob Kiesel 2018-09-21 09:25:43 -06:00 committed by Sébastien Crozet
parent 4b6a69bb99
commit 787d20cff4
3 changed files with 52 additions and 0 deletions

View File

@ -1166,6 +1166,26 @@ impl<N: Real, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
self.norm_squared().sqrt() self.norm_squared().sqrt()
} }
/// A synonym for the norm of this matrix.
///
/// Aka the length.
///
/// This function is simply implemented as a call to `norm()`
#[inline]
pub fn magnitude(&self) -> N {
self.norm()
}
/// A synonym for the squared norm of this matrix.
///
/// Aka the squared length.
///
/// This function is simply implemented as a call to `norm_squared()`
#[inline]
pub fn magnitude_squared(&self) -> N {
self.norm_squared()
}
/// Returns a normalized version of this matrix. /// Returns a normalized version of this matrix.
#[inline] #[inline]
pub fn normalize(&self) -> MatrixMN<N, R, C> pub fn normalize(&self) -> MatrixMN<N, R, C>

View File

@ -176,6 +176,26 @@ impl<N: Real> Quaternion<N> {
self.coords.norm() self.coords.norm()
} }
/// A synonym for the norm of this quaternion.
///
/// Aka the length.
///
/// This function is simply implemented as a call to `norm()`
#[inline]
pub fn magnitude(&self) -> N {
self.norm()
}
/// A synonym for the squared norm of this quaternion.
///
/// Aka the squared length.
///
/// This function is simply implemented as a call to `norm_squared()`
#[inline]
pub fn magnitude_squared(&self) -> N {
self.norm_squared()
}
/// The squared norm of this quaternion. /// The squared norm of this quaternion.
#[inline] #[inline]
pub fn norm_squared(&self) -> N { pub fn norm_squared(&self) -> N {

View File

@ -418,6 +418,18 @@ pub fn norm_squared<V: NormedSpace>(v: &V) -> V::Field {
v.norm_squared() v.norm_squared()
} }
/// A synonym function for `norm()` aka length.
#[inline]
pub fn magnitude<V: NormedSpace>(v: &V) -> V::Field {
v.norm()
}
/// A synonym function for `norm_squared()` aka length squared.
#[inline]
pub fn magnitude_squared<V: NormedSpace>(v: &V) -> V::Field {
v.norm_squared()
}
/// Computes the normalized version of the vector `v`. /// Computes the normalized version of the vector `v`.
#[inline] #[inline]
pub fn normalize<V: NormedSpace>(v: &V) -> V { pub fn normalize<V: NormedSpace>(v: &V) -> V {