diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-08 15:40:34 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-08 16:10:30 +0300 |
commit | a8ff8b64dc4d4bea9ec620920639440496dfcba0 (patch) | |
tree | c916476052252d831f7f4a562e87d5bc00922048 /source/blender/blenlib/BLI_float3.hh | |
parent | ff444da7c45403ac0d112042c9d1d0a1992168d4 (diff) |
BLI: add comparison operators and hash functions for float3, etc.
Diffstat (limited to 'source/blender/blenlib/BLI_float3.hh')
-rw-r--r-- | source/blender/blenlib/BLI_float3.hh | 18 |
1 files changed, 18 insertions, 0 deletions
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; |