From a8ff8b64dc4d4bea9ec620920639440496dfcba0 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 8 Jul 2020 14:40:34 +0200 Subject: BLI: add comparison operators and hash functions for float3, etc. --- source/blender/blenlib/BLI_float3.hh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source/blender/blenlib/BLI_float3.hh') diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh index 0edee600ef6..a36cedad41d 100644 --- a/source/blender/blenlib/BLI_float3.hh +++ b/source/blender/blenlib/BLI_float3.hh @@ -128,6 +128,16 @@ struct float3 { return stream; } + friend bool operator==(const float3 &a, const float3 &b) + { + return a.x == b.x && a.y == b.y && a.z == b.z; + } + + friend bool operator!=(const float3 &a, const float3 &b) + { + return !(a == b); + } + float normalize_and_get_length() { return normalize_v3(*this); @@ -178,6 +188,14 @@ struct float3 { z = -z; } + uint32_t hash() const + { + uint32_t x1 = *(uint32_t *)&x; + uint32_t x2 = *(uint32_t *)&y; + uint32_t x3 = *(uint32_t *)&z; + return (x1 * 435109) ^ (x2 * 380867) ^ (x3 * 1059217); + } + static float dot(const float3 &a, const float3 &b) { return a.x * b.x + a.y * b.y + a.z * b.z; -- cgit v1.2.3