From 9f2f619a21ea1a04e346426368839f189b5e11f3 Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 14 Oct 2025 13:00:28 +0300 Subject: [PATCH 1/2] Adds hash support for Vector2, Vector3, and Vector4 Implements `std::hash` specialization for `omath::Vector2`, `omath::Vector3`, and `omath::Vector4` with float components. This enables usage of these vector types as keys in hash-based containers, such as `std::unordered_map` and `std::unordered_set`. --- include/omath/linear_algebra/vector2.hpp | 15 +++++++++++++++ include/omath/linear_algebra/vector3.hpp | 1 + include/omath/linear_algebra/vector4.hpp | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/include/omath/linear_algebra/vector2.hpp b/include/omath/linear_algebra/vector2.hpp index 4dc96c77..2994144a 100644 --- a/include/omath/linear_algebra/vector2.hpp +++ b/include/omath/linear_algebra/vector2.hpp @@ -234,6 +234,21 @@ namespace omath }; } // namespace omath +template<> struct std::hash> +{ + [[nodiscard]] + std::size_t operator()(const omath::Vector2& vec) const noexcept + { + std::size_t hash = 0; + constexpr std::hash hasher; + + hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + + return hash; + } +}; + template struct std::formatter> // NOLINT(*-dcl58-cpp) { diff --git a/include/omath/linear_algebra/vector3.hpp b/include/omath/linear_algebra/vector3.hpp index 7e5838f3..77d60cfb 100644 --- a/include/omath/linear_algebra/vector3.hpp +++ b/include/omath/linear_algebra/vector3.hpp @@ -273,6 +273,7 @@ namespace omath template<> struct std::hash> { + [[nodiscard]] std::size_t operator()(const omath::Vector3& vec) const noexcept { std::size_t hash = 0; diff --git a/include/omath/linear_algebra/vector4.hpp b/include/omath/linear_algebra/vector4.hpp index d1e13772..25d6a6de 100644 --- a/include/omath/linear_algebra/vector4.hpp +++ b/include/omath/linear_algebra/vector4.hpp @@ -202,6 +202,22 @@ namespace omath }; } // namespace omath +template<> struct std::hash> +{ + [[nodiscard]] + std::size_t operator()(const omath::Vector4& vec) const noexcept + { + std::size_t hash = 0; + constexpr std::hash hasher; + + hash ^= hasher(vec.x) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= hasher(vec.y) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= hasher(vec.z) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= hasher(vec.w) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + return hash; + } +}; + template struct std::formatter> // NOLINT(*-dcl58-cpp) { From eb8688c90c1db4ad60e8e3b03c653b7ac7a4df51 Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 14 Oct 2025 13:06:23 +0300 Subject: [PATCH 2/2] Unifies orthographic matrix generation Consolidates the generation of left-handed and right-handed orthographic matrices into a shared implementation to reduce code duplication. --- include/omath/linear_algebra/mat.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/omath/linear_algebra/mat.hpp b/include/omath/linear_algebra/mat.hpp index b926edd8..a2721188 100644 --- a/include/omath/linear_algebra/mat.hpp +++ b/include/omath/linear_algebra/mat.hpp @@ -666,8 +666,7 @@ namespace omath } template [[nodiscard]] - Mat<4, 4, Type, St> mat_ortho_left_handed(const Type left, const Type right, - const Type bottom, const Type top, + Mat<4, 4, Type, St> mat_ortho_left_handed(const Type left, const Type right, const Type bottom, const Type top, const Type near, const Type far) noexcept { return @@ -680,9 +679,8 @@ namespace omath } template [[nodiscard]] - Mat<4, 4, Type, St> mat_ortho_right_handed(const Type left, const Type right, - const Type bottom, const Type top, - const Type near, const Type far) noexcept + Mat<4, 4, Type, St> mat_ortho_right_handed(const Type left, const Type right, const Type bottom, const Type top, + const Type near, const Type far) noexcept { return {