mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
[Core] Add is_same to types that have float components
Compares `NaN` as equal. Added to: * `AABB` * `Basis` * `Color` * `Plane` * `Projection` * `Quaternion` * `Rect2` * `Transform2D` * `Transform3D` * `Vector2` * `Vector3` * `Vector4` And added as a method in `Math`
This commit is contained in:
parent
eee39f004b
commit
e825085978
27 changed files with 99 additions and 87 deletions
|
|
@ -3139,32 +3139,20 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
|
|||
#define hash_compare_scalar(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar_base(p_lhs, p_rhs, true))
|
||||
|
||||
#define hash_compare_vector2(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).x, (p_rhs).x) && \
|
||||
hash_compare_scalar((p_lhs).y, (p_rhs).y))
|
||||
#define hash_compare_vector2(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_vector3(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).x, (p_rhs).x) && \
|
||||
hash_compare_scalar((p_lhs).y, (p_rhs).y) && \
|
||||
hash_compare_scalar((p_lhs).z, (p_rhs).z))
|
||||
#define hash_compare_vector3(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_vector4(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).x, (p_rhs).x) && \
|
||||
hash_compare_scalar((p_lhs).y, (p_rhs).y) && \
|
||||
hash_compare_scalar((p_lhs).z, (p_rhs).z) && \
|
||||
hash_compare_scalar((p_lhs).w, (p_rhs).w))
|
||||
#define hash_compare_vector4(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_quaternion(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).x, (p_rhs).x) && \
|
||||
hash_compare_scalar((p_lhs).y, (p_rhs).y) && \
|
||||
hash_compare_scalar((p_lhs).z, (p_rhs).z) && \
|
||||
hash_compare_scalar((p_lhs).w, (p_rhs).w))
|
||||
#define hash_compare_quaternion(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_color(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).r, (p_rhs).r) && \
|
||||
hash_compare_scalar((p_lhs).g, (p_rhs).g) && \
|
||||
hash_compare_scalar((p_lhs).b, (p_rhs).b) && \
|
||||
hash_compare_scalar((p_lhs).a, (p_rhs).a))
|
||||
#define hash_compare_color(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_packed_array(p_lhs, p_rhs, p_type, p_compare_func) \
|
||||
const Vector<p_type> &l = PackedArrayRef<p_type>::get_array(p_lhs); \
|
||||
|
|
@ -3235,13 +3223,7 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool s
|
|||
Transform2D *l = _data._transform2d;
|
||||
Transform2D *r = p_variant._data._transform2d;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!hash_compare_vector2(l->columns[i], r->columns[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case VECTOR3: {
|
||||
|
|
@ -3273,17 +3255,14 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool s
|
|||
const Plane *l = reinterpret_cast<const Plane *>(_data._mem);
|
||||
const Plane *r = reinterpret_cast<const Plane *>(p_variant._data._mem);
|
||||
|
||||
return hash_compare_vector3(l->normal, r->normal) &&
|
||||
hash_compare_scalar(l->d, r->d);
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case AABB: {
|
||||
const ::AABB *l = _data._aabb;
|
||||
const ::AABB *r = p_variant._data._aabb;
|
||||
|
||||
return hash_compare_vector3(l->position, r->position) &&
|
||||
hash_compare_vector3(l->size, r->size);
|
||||
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case QUATERNION: {
|
||||
|
|
@ -3297,38 +3276,20 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool s
|
|||
const Basis *l = _data._basis;
|
||||
const Basis *r = p_variant._data._basis;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!hash_compare_vector3(l->rows[i], r->rows[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case TRANSFORM3D: {
|
||||
const Transform3D *l = _data._transform3d;
|
||||
const Transform3D *r = p_variant._data._transform3d;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!hash_compare_vector3(l->basis.rows[i], r->basis.rows[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return hash_compare_vector3(l->origin, r->origin);
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
case PROJECTION: {
|
||||
const Projection *l = _data._projection;
|
||||
const Projection *r = p_variant._data._projection;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!hash_compare_vector4(l->columns[i], r->columns[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case COLOR: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue