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_color.hh | |
parent | ff444da7c45403ac0d112042c9d1d0a1992168d4 (diff) |
BLI: add comparison operators and hash functions for float3, etc.
Diffstat (limited to 'source/blender/blenlib/BLI_color.hh')
-rw-r--r-- | source/blender/blenlib/BLI_color.hh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_color.hh b/source/blender/blenlib/BLI_color.hh index 37f74edcf4c..1215affe837 100644 --- a/source/blender/blenlib/BLI_color.hh +++ b/source/blender/blenlib/BLI_color.hh @@ -51,6 +51,25 @@ struct Color4f { stream << "(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")"; return stream; } + + friend bool operator==(const Color4f &a, const Color4f &b) + { + return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; + } + + friend bool operator!=(const Color4f &a, const Color4f &b) + { + return !(a == b); + } + + uint32_t hash() const + { + uint32_t x1 = *(uint32_t *)&r; + uint32_t x2 = *(uint32_t *)&g; + uint32_t x3 = *(uint32_t *)&b; + uint32_t x4 = *(uint32_t *)&a; + return (x1 * 1283591) ^ (x2 * 850177) ^ (x3 * 735391) ^ (x4 * 442319); + } }; struct Color4b { @@ -89,6 +108,16 @@ struct Color4b { stream << "(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")"; return stream; } + + friend bool operator==(const Color4b &a, const Color4b &b) + { + return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; + } + + friend bool operator!=(const Color4b &a, const Color4b &b) + { + return !(a == b); + } }; } // namespace blender |