From 693a0adda06d197884058bc9fc543720968fe8f2 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Fri, 9 Nov 2012 17:30:18 +1000 Subject: [PATCH] Add dot product --- src/quaternion.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/quaternion.rs b/src/quaternion.rs index e1cd8cd..61adb1d 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -33,6 +33,8 @@ pub trait Quaternion { pure fn sub_q(other: &self) -> self; pure fn mul_q(other: &self) -> self; + pure fn dot(other: &self) -> T; + pure fn conjugate() -> self; pure fn inverse() -> self; pure fn length2() -> T; @@ -122,6 +124,14 @@ pub impl Quat: Quaternion { self.w * other.z + self.z * other.w + self.x * other.y - self.y * other.x) } + #[inline(always)] + pure fn dot(other: &Quat) -> T { + self.w * other.w + + self.x * other.x + + self.y * other.y + + self.z * other.z + } + #[inline(always)] pure fn conjugate() -> Quat { Quat::new(self.w, -self.x, -self.y, -self.z)