Add a default implementation for EuclideanVector::angle

This commit is contained in:
Brendan Zabarauskas 2016-04-04 20:20:31 +10:00
parent 3b55ad5f70
commit 40a3ad3185

View file

@ -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<Self::Scalar>;
/// Returns the angle between two vectors in radians.
fn angle(self, other: Self) -> Rad<Self::Scalar> {
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<S: BaseFloat> EuclideanVector for Vector4<S> {
fn dot(self, other: Vector4<S>) -> S {
Vector4::mul_element_wise(self, other).sum()
}
#[inline]
fn angle(self, other: Vector4<S>) -> Rad<S> {
Rad::acos(Self::dot(self, other) / (self.magnitude() * other.magnitude()))
}
}
impl<S: fmt::Debug> fmt::Debug for Vector2<S> {