SP3-16 Fixed vector subscript operator return type #60

Merged
direnbharwani merged 3 commits from SP3-16-Math into main 2022-09-28 17:09:59 +08:00
6 changed files with 12 additions and 24 deletions
Showing only changes of commit 170ae5ac6b - Show all commits

View File

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

View File

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

View File

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