From 787d20cff4b43e69da786ef6c77e26abc4fb09d0 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Fri, 21 Sep 2018 09:25:43 -0600 Subject: [PATCH] Add magnitude synonym functions for ease of use --- src/base/matrix.rs | 20 ++++++++++++++++++++ src/geometry/quaternion.rs | 20 ++++++++++++++++++++ src/lib.rs | 12 ++++++++++++ 3 files changed, 52 insertions(+) diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 2c7c673a..0fff3efc 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -1166,6 +1166,26 @@ impl> Matrix { 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. #[inline] pub fn normalize(&self) -> MatrixMN diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 47b62d6c..3196b94c 100644 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -176,6 +176,26 @@ impl Quaternion { 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. #[inline] pub fn norm_squared(&self) -> N { diff --git a/src/lib.rs b/src/lib.rs index 8268f682..a1a4a5b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -418,6 +418,18 @@ pub fn norm_squared(v: &V) -> V::Field { v.norm_squared() } +/// A synonym function for `norm()` aka length. +#[inline] +pub fn magnitude(v: &V) -> V::Field { + v.norm() +} + +/// A synonym function for `norm_squared()` aka length squared. +#[inline] +pub fn magnitude_squared(v: &V) -> V::Field { + v.norm_squared() +} + /// Computes the normalized version of the vector `v`. #[inline] pub fn normalize(v: &V) -> V {