Add dot product

This commit is contained in:
Brendan Zabarauskas 2012-11-09 17:30:18 +10:00
parent b074ecafbd
commit 693a0adda0

View file

@ -33,6 +33,8 @@ pub trait Quaternion<T> {
pure fn sub_q(other: &self) -> self; pure fn sub_q(other: &self) -> self;
pure fn mul_q(other: &self) -> self; pure fn mul_q(other: &self) -> self;
pure fn dot(other: &self) -> T;
pure fn conjugate() -> self; pure fn conjugate() -> self;
pure fn inverse() -> self; pure fn inverse() -> self;
pure fn length2() -> T; pure fn length2() -> T;
@ -122,6 +124,14 @@ pub impl<T:Copy Num NumCast Exp FuzzyEq> Quat<T>: Quaternion<T> {
self.w * other.z + self.z * other.w + self.x * other.y - self.y * other.x) self.w * other.z + self.z * other.w + self.x * other.y - self.y * other.x)
} }
#[inline(always)]
pure fn dot(other: &Quat<T>) -> T {
self.w * other.w +
self.x * other.x +
self.y * other.y +
self.z * other.z
}
#[inline(always)] #[inline(always)]
pure fn conjugate() -> Quat<T> { pure fn conjugate() -> Quat<T> {
Quat::new(self.w, -self.x, -self.y, -self.z) Quat::new(self.w, -self.x, -self.y, -self.z)