From 59b2e55ed5a71fdcbe7ecdd66b80b72b9e4346fd Mon Sep 17 00:00:00 2001 From: S6066 Date: Wed, 12 Oct 2016 17:56:46 +0200 Subject: [PATCH] Added hash for Vectors --- include/Nazara/Math/Vector2.hpp | 9 +++++++++ include/Nazara/Math/Vector2.inl | 24 ++++++++++++++++++++++++ include/Nazara/Math/Vector3.hpp | 9 +++++++++ include/Nazara/Math/Vector3.inl | 25 +++++++++++++++++++++++++ include/Nazara/Math/Vector4.hpp | 9 +++++++++ include/Nazara/Math/Vector4.inl | 26 ++++++++++++++++++++++++++ 6 files changed, 102 insertions(+) diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index e0ac1d68d..d3e8be8c5 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -8,6 +8,7 @@ #define NAZARA_VECTOR2_HPP #include +#include namespace Nz { @@ -119,6 +120,14 @@ template std::ostream& operator<<(std::ostream& out, const Nz::Vecto template Nz::Vector2 operator*(T scale, const Nz::Vector2& vec); template Nz::Vector2 operator/(T scale, const Nz::Vector2& vec); +namespace std +{ + +template +struct hash>; + +} + #include #endif // NAZARA_VECTOR2_HPP diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 80e588ba4..c602052f3 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -1057,6 +1057,30 @@ Nz::Vector2 operator/(T scale, const Nz::Vector2& vec) return Nz::Vector2(scale / vec.x, scale / vec.y); } +namespace std +{ + +template +struct hash> +{ + /*! + * \brief Specialisation of std to hash + * \return Result of the hash + * + * \param v Vector2 to hash + */ + + std::size_t operator()(const Nz::Vector2& v) const + { + std::size_t seed {}; + + Nz::HashCombine(seed, v.x); + Nz::HashCombine(seed, v.y); + + return seed; + } +}; + #undef F #include diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 4e6da14ec..cff16be55 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -8,6 +8,7 @@ #define NAZARA_VECTOR3_HPP #include +#include namespace Nz { @@ -141,6 +142,14 @@ template std::ostream& operator<<(std::ostream& out, const Nz::Vecto template Nz::Vector3 operator*(T scale, const Nz::Vector3& vec); template Nz::Vector3 operator/(T scale, const Nz::Vector3& vec); +namespace std +{ + +template +struct hash>; + +} + #include #endif // NAZARA_VECTOR3_HPP diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index c5a0155c7..41bd20400 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -1347,6 +1347,31 @@ Nz::Vector3 operator/(T scale, const Nz::Vector3& vec) return Nz::Vector3(scale / vec.x, scale / vec.y, scale / vec.z); } +namespace std +{ + +template +struct hash> +{ + /*! + * \brief Specialisation of std to hash + * \return Result of the hash + * + * \param v Vector3 to hash + */ + + std::size_t operator()(const Nz::Vector3& v) const + { + std::size_t seed {}; + + Nz::HashCombine(seed, v.x); + Nz::HashCombine(seed, v.y); + Nz::HashCombine(seed, v.z); + + return seed; + } +}; + #undef F #include diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 0f8e907fc..0c408b90e 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -8,6 +8,7 @@ #define NAZARA_VECTOR4_HPP #include +#include namespace Nz { @@ -117,6 +118,14 @@ template std::ostream& operator<<(std::ostream& out, const Nz::Vecto template Nz::Vector4 operator*(T scale, const Nz::Vector4& vec); template Nz::Vector4 operator/(T scale, const Nz::Vector4& vec); +namespace std +{ + +template +struct hash>; + +} + #include #endif // NAZARA_VECTOR4_HPP diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 73a9a0802..05a28532b 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -1120,6 +1120,32 @@ Nz::Vector4 operator/(T scale, const Nz::Vector4& vec) return Nz::Vector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); } +namespace std +{ + +template +struct hash> +{ + /*! + * \brief Specialisation of std to hash + * \return Result of the hash + * + * \param v Vector4 to hash + */ + + std::size_t operator()(const Nz::Vector4& v) const + { + std::size_t seed {}; + + Nz::HashCombine(seed, v.x); + Nz::HashCombine(seed, v.y); + Nz::HashCombine(seed, v.z); + Nz::HashCombine(seed, v.w); + + return seed; + } +}; + #undef F #include