From 40a3ad31852f8d065d2a0baa77254dbcaaaf7d0e Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 4 Apr 2016 20:20:31 +1000 Subject: [PATCH] Add a default implementation for EuclideanVector::angle --- src/vector.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/vector.rs b/src/vector.rs index 606f5ed..a6ef745 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -560,8 +560,10 @@ pub trait EuclideanVector: Vector + Sized where Float::sqrt(self.magnitude2()) } - /// The angle between the vector and `other`, in radians. - fn angle(self, other: Self) -> Rad; + /// Returns the angle between two vectors in radians. + fn angle(self, other: Self) -> Rad { + Rad::acos(Self::dot(self, other) / (self.magnitude() * other.magnitude())) + } /// Returns a vector with the same direction, but with a magnitude of `1`. #[inline] @@ -623,11 +625,6 @@ impl EuclideanVector for Vector4 { fn dot(self, other: Vector4) -> S { Vector4::mul_element_wise(self, other).sum() } - - #[inline] - fn angle(self, other: Vector4) -> Rad { - Rad::acos(Self::dot(self, other) / (self.magnitude() * other.magnitude())) - } } impl fmt::Debug for Vector2 {