From 17718fa409c9d2bbc405de40757da0f983d043f4 Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 29 Dec 2023 12:32:46 -0500 Subject: [PATCH] Implement Vector2 static member methods --- include/J3ML/LinearAlgebra/Vector2.h | 10 +++++----- src/J3ML/LinearAlgebra/Vector2.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/J3ML/LinearAlgebra/Vector2.h b/include/J3ML/LinearAlgebra/Vector2.h index d65bd6e..1bd0abb 100644 --- a/include/J3ML/LinearAlgebra/Vector2.h +++ b/include/J3ML/LinearAlgebra/Vector2.h @@ -56,22 +56,22 @@ namespace LinearAlgebra { // Returns the length of the vector, which is sqrt(x^2 + y^2) float Magnitude() const; - static float Magnitude(const Vector2& of) { return of.Magnitude();} + static float Magnitude(const Vector2& of); // Returns a float value equal to the magnitudes of the two vectors multiplied together and then multiplied by the cosine of the angle between them. // For normalized vectors, dot returns 1 if they point in exactly the same direction, // -1 if they point in completely opposite directions, and 0 if the vectors are perpendicular. float Dot(const Vector2& rhs) const; - static float Dot(const Vector2& lhs, const Vector2& rhs) { return lhs.Dot(rhs); } + static float Dot(const Vector2& lhs, const Vector2& rhs); // Projects one vector onto another and returns the result. (IDK) Vector2 Project(const Vector2& rhs) const; // @see Project - static Vector2 Project(const Vector2& lhs, const Vector2& rhs) { return lhs.Project(rhs); } + static Vector2 Project(const Vector2& lhs, const Vector2& rhs); // Returns a copy of this vector, resized to have a magnitude of 1, while preserving "direction" Vector2 Normalize() const; - static Vector2 Normalize(const Vector2& of) { return of.Normalize(); } + static Vector2 Normalize(const Vector2& of); // Linearly interpolates between two points. // Interpolates between the points and b by the interpolant t. @@ -79,7 +79,7 @@ namespace LinearAlgebra { // This is most commonly used to find a point some fraction of the wy along a line between two endpoints (eg. to move an object gradually between those points). Vector2 Lerp(const Vector2& rhs, float alpha) const; // @see Lerp - static Vector2 Lerp(const Vector2& lhs, const Vector2& rhs, float alpha) { return lhs.Lerp(rhs, alpha); } + static Vector2 Lerp(const Vector2& lhs, const Vector2& rhs, float alpha); float AngleBetween(const Vector2& rhs) const; static float AngleBetween(const Vector2& lhs, const Vector2& rhs); diff --git a/src/J3ML/LinearAlgebra/Vector2.cpp b/src/J3ML/LinearAlgebra/Vector2.cpp index 62b0a41..9cd4ad9 100644 --- a/src/J3ML/LinearAlgebra/Vector2.cpp +++ b/src/J3ML/LinearAlgebra/Vector2.cpp @@ -188,5 +188,15 @@ namespace LinearAlgebra { return dot*dot <= epsilonSq * LengthSquared() * other.LengthSquared(); } + Vector2 Vector2::Normalize(const Vector2 &of) { return of.Normalize(); } + + Vector2 Vector2::Project(const Vector2 &lhs, const Vector2 &rhs) { return lhs.Project(rhs); } + + float Vector2::Dot(const Vector2 &lhs, const Vector2 &rhs) { return lhs.Dot(rhs); } + + float Vector2::Magnitude(const Vector2 &of) { return of.Magnitude();} + + Vector2 Vector2::Lerp(const Vector2 &lhs, const Vector2 &rhs, float alpha) { return lhs.Lerp(rhs, alpha); } + } \ No newline at end of file