Skip to content

Commit 29c2261

Browse files
[Core] Add missing HashMapComparatorDefault cases
Added for: * `Vector4` * `Quaternion` * `Color` Ensures these handles `NaN` correctly
1 parent 76a1359 commit 29c2261

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

core/templates/hashfuncs.h

+23
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
#define HASHFUNCS_H
3333

3434
#include "core/math/aabb.h"
35+
#include "core/math/color.h"
3536
#include "core/math/math_defs.h"
3637
#include "core/math/math_funcs.h"
38+
#include "core/math/quaternion.h"
3739
#include "core/math/rect2.h"
3840
#include "core/math/rect2i.h"
3941
#include "core/math/vector2.h"
@@ -413,6 +415,13 @@ struct HashMapComparatorDefault<double> {
413415
}
414416
};
415417

418+
template <>
419+
struct HashMapComparatorDefault<Color> {
420+
static bool compare(const Color &p_lhs, const Color &p_rhs) {
421+
return ((p_lhs.r == p_rhs.r) || (Math::is_nan(p_lhs.r) && Math::is_nan(p_rhs.r))) && ((p_lhs.g == p_rhs.g) || (Math::is_nan(p_lhs.g) && Math::is_nan(p_rhs.g))) && ((p_lhs.b == p_rhs.b) || (Math::is_nan(p_lhs.b) && Math::is_nan(p_rhs.b))) && ((p_lhs.a == p_rhs.a) || (Math::is_nan(p_lhs.a) && Math::is_nan(p_rhs.a)));
422+
}
423+
};
424+
416425
template <>
417426
struct HashMapComparatorDefault<Vector2> {
418427
static bool compare(const Vector2 &p_lhs, const Vector2 &p_rhs) {
@@ -427,6 +436,20 @@ struct HashMapComparatorDefault<Vector3> {
427436
}
428437
};
429438

439+
template <>
440+
struct HashMapComparatorDefault<Vector4> {
441+
static bool compare(const Vector4 &p_lhs, const Vector4 &p_rhs) {
442+
return ((p_lhs.x == p_rhs.x) || (Math::is_nan(p_lhs.x) && Math::is_nan(p_rhs.x))) && ((p_lhs.y == p_rhs.y) || (Math::is_nan(p_lhs.y) && Math::is_nan(p_rhs.y))) && ((p_lhs.z == p_rhs.z) || (Math::is_nan(p_lhs.z) && Math::is_nan(p_rhs.z))) && ((p_lhs.w == p_rhs.w) || (Math::is_nan(p_lhs.w) && Math::is_nan(p_rhs.w)));
443+
}
444+
};
445+
446+
template <>
447+
struct HashMapComparatorDefault<Quaternion> {
448+
static bool compare(const Quaternion &p_lhs, const Quaternion &p_rhs) {
449+
return ((p_lhs.x == p_rhs.x) || (Math::is_nan(p_lhs.x) && Math::is_nan(p_rhs.x))) && ((p_lhs.y == p_rhs.y) || (Math::is_nan(p_lhs.y) && Math::is_nan(p_rhs.y))) && ((p_lhs.z == p_rhs.z) || (Math::is_nan(p_lhs.z) && Math::is_nan(p_rhs.z))) && ((p_lhs.w == p_rhs.w) || (Math::is_nan(p_lhs.w) && Math::is_nan(p_rhs.w)));
450+
}
451+
};
452+
430453
constexpr uint32_t HASH_TABLE_SIZE_MAX = 29;
431454

432455
inline constexpr uint32_t hash_table_size_primes[HASH_TABLE_SIZE_MAX] = {

0 commit comments

Comments
 (0)