From cea162df8c2d48218dcdd00cef45c69ac12f1c36 Mon Sep 17 00:00:00 2001 From: Matthew Plant Date: Fri, 16 Jun 2017 11:52:51 -0700 Subject: [PATCH] Added project_on to InnerSpace --- src/structure.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/structure.rs b/src/structure.rs index 49c271c..dc808ae 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -246,6 +246,15 @@ pub trait InnerSpace: VectorSpace where fn lerp(self, other: Self, amount: Self::Scalar) -> Self { self + ((other - self) * amount) } + + /// Returns the + /// [vector projection](https://en.wikipedia.org/wiki/Vector_projection) + /// of the current inner space projected onto the supplied argument. + #[inline] + #[must_use] + fn project_on(self, other: Self) -> Self { + other * (self.dot(other) / other.magnitude2()) + } } /// Points in a [Euclidean space](https://en.wikipedia.org/wiki/Euclidean_space)