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())) } }