From fb5228f14f0c13ea0d50d085d8a94eb0059f6e13 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 27 Mar 2016 16:25:03 +1100 Subject: [PATCH] Clean up some function calls --- src/vector.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/vector.rs b/src/vector.rs index d0bab1d..065f27b 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -134,7 +134,7 @@ pub trait Vector: Copy + Clone where } /// Dot product of two vectors. -#[inline] pub fn dot(a: V, b: V) -> V::Scalar { a.dot(b) } +#[inline] pub fn dot(a: V, b: V) -> V::Scalar { V::dot(a, b) } /// A 2-dimensional vector. /// @@ -487,7 +487,7 @@ pub trait EuclideanVector: Vector + Sized where /// Returns `true` if the vector is perpendicular (at right angles) to the /// other vector. fn is_perpendicular(self, other: Self) -> bool { - self.dot(other).approx_eq(&Self::Scalar::zero()) + Self::dot(self, other).approx_eq(&Self::Scalar::zero()) } /// Returns the squared magnitude of the vector. @@ -497,14 +497,16 @@ pub trait EuclideanVector: Vector + Sized where /// efficiently. #[inline] fn magnitude2(self) -> Self::Scalar { - self.dot(self) + Self::dot(self, self) } /// The distance from the tail to the tip of the vector. #[inline] fn magnitude(self) -> Self::Scalar { - // FIXME: Not sure why this annotation is needed - <::Scalar as ::rust_num::Float>::sqrt(self.dot(self)) + use rust_num::Float; + + // FIXME: Not sure why we can't use method syntax for `sqrt` here... + Float::sqrt(self.magnitude2()) } /// The angle between the vector and `other`, in radians. @@ -536,21 +538,21 @@ pub trait EuclideanVector: Vector + Sized where impl EuclideanVector for Vector2 { #[inline] fn angle(self, other: Vector2) -> Rad { - Rad::atan2(self.perp_dot(other), self.dot(other)) + Rad::atan2(Self::perp_dot(self, other), Self::dot(self, other)) } } impl EuclideanVector for Vector3 { #[inline] fn angle(self, other: Vector3) -> Rad { - Rad::atan2(self.cross(other).magnitude(), self.dot(other)) + Rad::atan2(self.cross(other).magnitude(), Self::dot(self, other)) } } impl EuclideanVector for Vector4 { #[inline] fn angle(self, other: Vector4) -> Rad { - Rad::acos(self.dot(other) / (self.magnitude() * other.magnitude())) + Rad::acos(Self::dot(self, other) / (self.magnitude() * other.magnitude())) } }