Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-07-08 15:40:34 +0300
committerJacques Lucke <jacques@blender.org>2020-07-08 16:10:30 +0300
commita8ff8b64dc4d4bea9ec620920639440496dfcba0 (patch)
treec916476052252d831f7f4a562e87d5bc00922048
parentff444da7c45403ac0d112042c9d1d0a1992168d4 (diff)
BLI: add comparison operators and hash functions for float3, etc.
-rw-r--r--source/blender/blenlib/BLI_color.hh29
-rw-r--r--source/blender/blenlib/BLI_float2.hh10
-rw-r--r--source/blender/blenlib/BLI_float3.hh18
-rw-r--r--source/blender/blenlib/BLI_hash.hh7
4 files changed, 64 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
diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh
index 94da5d18ad2..7bf928e7db5 100644
--- a/source/blender/blenlib/BLI_float2.hh
+++ b/source/blender/blenlib/BLI_float2.hh
@@ -79,6 +79,16 @@ struct float2 {
stream << "(" << v.x << ", " << v.y << ")";
return stream;
}
+
+ friend bool operator==(const float2 &a, const float2 &b)
+ {
+ return a.x == b.x && a.y == b.y;
+ }
+
+ friend bool operator!=(const float2 &a, const float2 &b)
+ {
+ return !(a == b);
+ }
};
} // namespace blender
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;
diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh
index 49e619ff1bc..5cd4ce3c1a9 100644
--- a/source/blender/blenlib/BLI_hash.hh
+++ b/source/blender/blenlib/BLI_hash.hh
@@ -154,6 +154,13 @@ template<> struct DefaultHash<float> {
}
};
+template<> struct DefaultHash<bool> {
+ uint32_t operator()(bool value) const
+ {
+ return (uint32_t)(value != false) * 1298191;
+ }
+};
+
inline uint32_t hash_string(StringRef str)
{
uint32_t hash = 5381;