Implement by-Reference operators

This commit is contained in:
2024-02-14 18:12:02 -05:00
parent efead577a5
commit fd2e3f894a
10 changed files with 191 additions and 12 deletions

View File

@@ -6,9 +6,6 @@
namespace J3ML::LinearAlgebra {
using namespace J3ML;
/// A 2D (x, y) ordered pair.
class Vector2 {
public:
@@ -16,6 +13,7 @@ namespace J3ML::LinearAlgebra {
Vector2();
/// Constructs a new Vector2 with the value (X, Y)
Vector2(float X, float Y);
Vector2(float* xyPtr);
Vector2(const Vector2& rhs); // Copy Constructor
//Vector2(Vector2&&) = default; // Move Constructor
@@ -31,6 +29,11 @@ namespace J3ML::LinearAlgebra {
void SetX(float newX);
void SetY(float newY);
float* ptr()
{
return &x;
}
Vector2 Abs() const;
bool IsWithinMarginOfError(const Vector2& rhs, float margin=0.001f) const;
@@ -39,7 +42,8 @@ namespace J3ML::LinearAlgebra {
bool IsZero(float epsilonSq = 1e-6f) const;
bool IsPerpendicular(const Vector2& other, float epsilonSq=1e-5f) const;
float operator[](std::size_t index);
float operator[](std::size_t index) const;
float &operator[](std::size_t index);
bool operator == (const Vector2& rhs) const;
bool operator != (const Vector2& rhs) const;
@@ -74,10 +78,6 @@ namespace J3ML::LinearAlgebra {
static float Magnitude(const Vector2& of);
bool IsFinite() const;
static bool IsFinite(const Vector2& v);