diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 9e6fa53e9..a448cd3ce 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -66,6 +66,8 @@ namespace Nz constexpr Vector2 operator*(T scale) const; constexpr Vector2 operator/(const Vector2& vec) const; constexpr Vector2 operator/(T scale) const; + constexpr Vector2 operator%(const Vector2& vec) const; + constexpr Vector2 operator%(T mod) const; constexpr Vector2& operator=(const Vector2&) = default; constexpr Vector2& operator=(Vector2&&) = default; @@ -76,6 +78,8 @@ namespace Nz constexpr Vector2& operator*=(T scale); constexpr Vector2& operator/=(const Vector2& vec); constexpr Vector2& operator/=(T scale); + constexpr Vector2& operator%=(const Vector2& vec); + constexpr Vector2& operator%=(T mod); constexpr bool operator==(const Vector2& vec) const; constexpr bool operator!=(const Vector2& vec) const; @@ -111,8 +115,9 @@ namespace Nz template std::ostream& operator<<(std::ostream& out, const Vector2& vec); - template constexpr Vector2 operator*(T scale, const Nz::Vector2& vec); - template constexpr Vector2 operator/(T scale, const Nz::Vector2& vec); + template constexpr Vector2 operator*(T scale, const Vector2& vec); + template constexpr Vector2 operator/(T scale, const Vector2& vec); + template constexpr Vector2 operator%(T mod, const Vector2& vec); } namespace std diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index a7161f50c..5547f615c 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -396,6 +396,18 @@ namespace Nz return Vector2(x / scale, y / scale); } + template + constexpr Vector2 Vector2::operator%(const Vector2& vec) const + { + return Vector2(Mod(x, vec.x), Mod(y, vec.y)); + } + + template + constexpr Vector2 Vector2::operator%(T mod) const + { + return Vector2(Mod(x, mod), Mod(y, mod)); + } + /*! * \brief Adds the components of other vector to this vector * \return A reference to this vector where components are the sum of this vector and the other one @@ -486,6 +498,24 @@ namespace Nz return *this; } + template + constexpr Vector2& Vector2::operator%=(const Vector2& vec) + { + x = Mod(x, vec.x); + y = Mod(y, vec.y); + + return *this; + } + + template + constexpr Vector2& Vector2::operator%=(T value) + { + x = Mod(x, value); + y = Mod(y, value); + + return *this; + } + /*! * \brief Compares the vector to other one * \return true if the vectors are the same @@ -724,6 +754,12 @@ namespace Nz return Vector2(scale / vec.x, scale / vec.y); } + template + constexpr Vector2 operator%(T mod, const Vector2& vec) + { + return Vector2(Mod(mod, vec.x), Mod(mod, vec.y)); + } + /*! * \brief Serializes a Vector2 * \return true if successfully serialized @@ -782,3 +818,4 @@ namespace std } #include +#include "Vector2.hpp" diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index db1a7b54a..e67a32f85 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -70,6 +70,8 @@ namespace Nz constexpr Vector3 operator*(T scale) const; constexpr Vector3 operator/(const Vector3& vec) const; constexpr Vector3 operator/(T scale) const; + constexpr Vector3 operator%(const Vector3& vec) const; + constexpr Vector3 operator%(T mod) const; constexpr Vector3& operator=(const Vector3&) = default; constexpr Vector3& operator=(Vector3&&) = default; @@ -80,6 +82,8 @@ namespace Nz constexpr Vector3& operator*=(T scale); constexpr Vector3& operator/=(const Vector3& vec); constexpr Vector3& operator/=(T scale); + constexpr Vector3& operator%=(const Vector3& vec); + constexpr Vector3& operator%=(T mod); constexpr bool operator==(const Vector3& vec) const; constexpr bool operator!=(const Vector3& vec) const; @@ -129,6 +133,7 @@ namespace Nz template constexpr Vector3 operator*(T scale, const Vector3& vec); template constexpr Vector3 operator/(T scale, const Vector3& vec); + template constexpr Vector3 operator%(T scale, const Vector3& vec); } namespace std diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index d79e4b818..8ae783360 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -464,6 +464,18 @@ namespace Nz return Vector3(x / scale, y / scale, z / scale); } + template + constexpr Vector3 Vector3::operator%(const Vector3& vec) const + { + return Vector3(Mod(x, vec.x), Mod(y, vec.y), Mod(z, vec.z)); + } + + template + constexpr Vector3 Vector3::operator%(T mod) const + { + return Vector3(Mod(x, mod), Mod(y, mod), Mod(z, mod)); + } + /*! * \brief Adds the components of other vector to this vector * \return A reference to this vector where components are the sum of this vector and the other one @@ -560,6 +572,26 @@ namespace Nz return *this; } + template + constexpr Vector3& Vector3::operator%=(const Vector3& vec) + { + x = Mod(x, vec.x); + y = Mod(y, vec.y); + z = Mod(z, vec.z); + + return *this; + } + + template + constexpr Vector3& Vector3::operator%=(T mod) + { + x = Mod(x, mod); + y = Mod(y, mod); + z = Mod(z, mod); + + return *this; + } + /*! * \brief Compares the vector to other one * \return true if the vectors are the same @@ -976,6 +1008,12 @@ namespace Nz { return Vector3(scale / vec.x, scale / vec.y, scale / vec.z); } + + template + constexpr Vector3 operator%(T mod, const Vector3& vec) + { + return Vector3(Mod(mod, vec.x), Mod(mod, vec.y), Mod(mod, vec.z)); + } } namespace std @@ -989,7 +1027,6 @@ namespace std * * \param v Vector3 to hash */ - std::size_t operator()(const Nz::Vector3& v) const { return Nz::HashCombine(v.x, v.y, v.z); diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 8a766e09c..d5ad06f72 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -66,6 +66,8 @@ namespace Nz constexpr Vector4 operator*(T scale) const; constexpr Vector4 operator/(const Vector4& vec) const; constexpr Vector4 operator/(T scale) const; + constexpr Vector4 operator%(const Vector4& vec) const; + constexpr Vector4 operator%(T mod) const; constexpr Vector4& operator+=(const Vector4& vec); constexpr Vector4& operator-=(const Vector4& vec); @@ -73,6 +75,8 @@ namespace Nz constexpr Vector4& operator*=(T scale); constexpr Vector4& operator/=(const Vector4& vec); constexpr Vector4& operator/=(T scale); + constexpr Vector4& operator%=(const Vector4& vec); + constexpr Vector4& operator%=(T mod); constexpr bool operator==(const Vector4& vec) const; constexpr bool operator!=(const Vector4& vec) const; @@ -109,6 +113,7 @@ namespace Nz template constexpr Vector4 operator*(T scale, const Vector4& vec); template constexpr Vector4 operator/(T scale, const Vector4& vec); + template constexpr Vector4 operator%(T mod, const Vector4& vec); } namespace std diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index b9ccd8976..8c5cddccf 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -400,6 +400,18 @@ namespace Nz return Vector4(x / scale, y / scale, z / scale, w / scale); } + template + constexpr Vector4 Vector4::operator%(const Vector4& vec) const + { + return Vector4(Mod(x, vec.x), Mod(y, vec.y), Mod(z, vec.z), Mod(w, vec.w)); + } + + template + constexpr Vector4 Vector4::operator%(T mod) const + { + return Vector4(Mod(x, mod), Mod(y, mod), Mod(z, mod), Mod(z, mod)); + } + /*! * \brief Adds the components of other vector to this vector * \return A reference to this vector where components are the sum of this vector and the other one @@ -501,6 +513,28 @@ namespace Nz return *this; } + + template + constexpr Vector4& Vector4::operator%=(const Vector4& vec) + { + x = Mod(x, vec.x); + y = Mod(y, vec.y); + z = Mod(z, vec.z); + w = Mod(w, vec.w); + + return *this; + } + + template + constexpr Vector4& Vector4::operator%=(T mod) + { + x = Mod(x, mod); + y = Mod(y, mod); + z = Mod(z, mod); + w = Mod(w, mod); + + return *this; + } /*! * \brief Compares the vector to other one @@ -781,7 +815,7 @@ namespace Nz template constexpr Vector4 operator*(T scale, const Vector4& vec) { - return Nz::Vector4(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w); + return Vector4(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w); } /*! @@ -793,7 +827,13 @@ namespace Nz template constexpr Vector4 operator/(T scale, const Vector4& vec) { - return Nz::Vector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); + return Vector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); + } + + template + constexpr Vector4 operator%(T mod, const Vector4& vec) + { + return Vector4(Mod(mod, vec.x), Mod(mod, vec.y), Mod(mod, vec.z), Mod(mod, vec.w)); } }