Merge pull request #60 from SHADE-DP/SP3-16-Math

SP3-16 Fixed vector subscript operator return type
BUGFIX

SHVec2, 3 & 4 (non-const) subscript operators now return a reference to the element
This commit is contained in:
XiaoQiDigipen 2022-09-28 17:09:58 +08:00 committed by GitHub
commit 2ce927d471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 24 deletions

View File

@ -165,7 +165,7 @@ namespace SHADE
return XMVector2NotEqual(V1, V2); return XMVector2NotEqual(V1, V2);
} }
float SHVec2::operator[](int index) float& SHVec2::operator[](int index)
{ {
if (index >= SIZE || index < 0) if (index >= SIZE || index < 0)
throw std::invalid_argument("Index out of range!"); throw std::invalid_argument("Index out of range!");
@ -174,11 +174,10 @@ namespace SHADE
{ {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
default: return 0.0f;
} }
} }
float SHVec2::operator[](size_t index) float& SHVec2::operator[](size_t index)
{ {
if (index >= SIZE) if (index >= SIZE)
throw std::invalid_argument("Index out of range!"); throw std::invalid_argument("Index out of range!");
@ -187,7 +186,6 @@ namespace SHADE
{ {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
default: return 0.0f;
} }
} }
@ -200,7 +198,6 @@ namespace SHADE
{ {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
default: return 0.0f;
} }
} }
@ -213,7 +210,6 @@ namespace SHADE
{ {
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
default: return 0.0f;
} }
} }

View File

@ -81,8 +81,8 @@ namespace SHADE
[[nodiscard]] bool operator== (const SHVec2& rhs) const noexcept; [[nodiscard]] bool operator== (const SHVec2& rhs) const noexcept;
[[nodiscard]] bool operator!= (const SHVec2& rhs) const noexcept; [[nodiscard]] bool operator!= (const SHVec2& rhs) const noexcept;
[[nodiscard]] float operator[] (int index); [[nodiscard]] float& operator[] (int index);
[[nodiscard]] float operator[] (size_t index); [[nodiscard]] float& operator[] (size_t index);
[[nodiscard]] float operator[] (int index) const; [[nodiscard]] float operator[] (int index) const;
[[nodiscard]] float operator[] (size_t index) const; [[nodiscard]] float operator[] (size_t index) const;

View File

@ -171,7 +171,7 @@ namespace SHADE
return XMVector3NotEqual(V1, V2); return XMVector3NotEqual(V1, V2);
} }
float SHVec3::operator[](int index) float& SHVec3::operator[](int index)
{ {
if (index >= SIZE || index < 0) if (index >= SIZE || index < 0)
throw std::invalid_argument("Index out of range!"); throw std::invalid_argument("Index out of range!");
@ -181,11 +181,10 @@ namespace SHADE
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
default: return 0.0f;
} }
} }
float SHVec3::operator[](size_t index) float& SHVec3::operator[](size_t index)
{ {
if (index >= SIZE) if (index >= SIZE)
throw std::invalid_argument("Index out of range!"); throw std::invalid_argument("Index out of range!");
@ -195,7 +194,6 @@ namespace SHADE
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
default: return 0.0f;
} }
} }
@ -209,7 +207,6 @@ namespace SHADE
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
default: return 0.0f;
} }
} }
@ -223,7 +220,6 @@ namespace SHADE
case 0: return x; case 0: return x;
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
default: return 0.0f;
} }
} }

View File

@ -86,8 +86,8 @@ namespace SHADE
[[nodiscard]] bool operator== (const SHVec3& rhs) const noexcept; [[nodiscard]] bool operator== (const SHVec3& rhs) const noexcept;
[[nodiscard]] bool operator!= (const SHVec3& rhs) const noexcept; [[nodiscard]] bool operator!= (const SHVec3& rhs) const noexcept;
[[nodiscard]] float operator[] (int index); [[nodiscard]] float& operator[] (int index);
[[nodiscard]] float operator[] (size_t index); [[nodiscard]] float& operator[] (size_t index);
[[nodiscard]] float operator[] (int index) const; [[nodiscard]] float operator[] (int index) const;
[[nodiscard]] float operator[] (size_t index) const; [[nodiscard]] float operator[] (size_t index) const;

View File

@ -161,7 +161,7 @@ namespace SHADE
return XMVector4NotEqual(V1, V2); return XMVector4NotEqual(V1, V2);
} }
float SHVec4::operator[](int index) float& SHVec4::operator[](int index)
{ {
if (index >= SIZE || index < 0) if (index >= SIZE || index < 0)
throw std::invalid_argument("Index out of range!"); throw std::invalid_argument("Index out of range!");
@ -172,11 +172,10 @@ namespace SHADE
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
case 3: return w; case 3: return w;
default: return 0.0f;
} }
} }
float SHVec4::operator[](size_t index) float& SHVec4::operator[](size_t index)
{ {
if (index >= SIZE) if (index >= SIZE)
throw std::invalid_argument("Index out of range!"); throw std::invalid_argument("Index out of range!");
@ -187,7 +186,6 @@ namespace SHADE
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
case 3: return w; case 3: return w;
default: return 0.0f;
} }
} }
@ -202,7 +200,6 @@ namespace SHADE
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
case 3: return w; case 3: return w;
default: return 0.0f;
} }
} }
@ -217,7 +214,6 @@ namespace SHADE
case 1: return y; case 1: return y;
case 2: return z; case 2: return z;
case 3: return w; case 3: return w;
default: return 0.0f;
} }
} }

View File

@ -80,8 +80,8 @@ namespace SHADE
[[nodiscard]] bool operator== (const SHVec4& rhs) const noexcept; [[nodiscard]] bool operator== (const SHVec4& rhs) const noexcept;
[[nodiscard]] bool operator!= (const SHVec4& rhs) const noexcept; [[nodiscard]] bool operator!= (const SHVec4& rhs) const noexcept;
[[nodiscard]] float operator[] (int index); [[nodiscard]] float& operator[] (int index);
[[nodiscard]] float operator[] (size_t index); [[nodiscard]] float& operator[] (size_t index);
[[nodiscard]] float operator[] (int index) const; [[nodiscard]] float operator[] (int index) const;
[[nodiscard]] float operator[] (size_t index) const; [[nodiscard]] float operator[] (size_t index) const;