Implement Vector2 static member methods

This commit is contained in:
2023-12-29 12:32:46 -05:00
parent 1ed11aa3db
commit 17718fa409
2 changed files with 15 additions and 5 deletions

View File

@@ -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);

View File

@@ -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); }
}