1
0
forked from josh/j3ml

Implement Vector2Tests

This commit is contained in:
2023-12-29 01:02:57 -05:00
parent fd4cc4723b
commit d2960b1dc4
9 changed files with 242 additions and 178 deletions

View File

@@ -1,12 +1,8 @@
#pragma once
#include <J3ML/LinearAlgebra.h>
#include <cstddef>
namespace LinearAlgebra {
// A 2D (x, y) ordered pair.
class Vector2 {
public:
@@ -16,12 +12,7 @@ namespace LinearAlgebra {
Vector2(float X, float Y);
Vector2(const Vector2& rhs); // Copy Constructor
Vector2(Vector2&&) = default; // Move Constructor
float GetX() const;
float GetY() const;
#if MUTABLE
void SetX(float newX) { x = newX;}
void SetY(float newY) { y = newY; }
#endif
static const Vector2 Zero;
static const Vector2 Up;
static const Vector2 Left;
@@ -29,16 +20,18 @@ namespace LinearAlgebra {
static const Vector2 Right;
static const Vector2 NaN;
float operator[](std::size_t index);
float GetX() const;
float GetY() const;
void SetX(float newX);
void SetY(float newY);
bool IsWithinMarginOfError(const Vector2& rhs, float margin=0.001f) const;
bool IsNormalized(float epsilonSq = 1e-5f) const;
bool IsZero(float epsilonSq = 1e-6f) const;
bool IsFinite() const;
bool IsPerpendicular(const Vector2& other, float epsilonSq=1e-5f) const;
float operator[](std::size_t index);
bool operator == (const Vector2& rhs) const;
bool operator != (const Vector2& rhs) const;
@@ -125,12 +118,8 @@ namespace LinearAlgebra {
Vector2& operator/=(float scalar);
public:
#if MUTABLE
float x = 0;
float y = 0;
#else
float x = 0;
float y = 0;
#endif
};
}