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

@@ -15,13 +15,21 @@ namespace J3ML::LinearAlgebra {
Vector2::Vector2(const Vector2& rhs): x(rhs.x), y(rhs.y)
{}
float Vector2::operator[](std::size_t index)
float Vector2::operator[](std::size_t index) const
{
assert(index < 2);
if (index == 0) return x;
if (index == 1) return y;
return 0;
}
float &Vector2::operator[](std::size_t index)
{
assert(index < 2);
if (index == 0) return x;
if (index == 1) return y;
}
bool Vector2::IsWithinMarginOfError(const Vector2& rhs, float margin) const
{
return this->Distance(rhs) <= margin;