Skip to content

Commit a13067e

Browse files
committed
Merge pull request #97553 from AThousandShips/semantic_equal
[Core] Add `is_same` to types that have float components
2 parents 8d1c1c5 + e825085 commit a13067e

27 files changed

+103
-91
lines changed

core/math/aabb.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ bool AABB::is_equal_approx(const AABB &p_aabb) const {
7676
return position.is_equal_approx(p_aabb.position) && size.is_equal_approx(p_aabb.size);
7777
}
7878

79+
bool AABB::is_same(const AABB &p_aabb) const {
80+
return position.is_same(p_aabb.position) && size.is_same(p_aabb.size);
81+
}
82+
7983
bool AABB::is_finite() const {
8084
return position.is_finite() && size.is_finite();
8185
}

core/math/aabb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct [[nodiscard]] AABB {
6262
bool operator!=(const AABB &p_rval) const;
6363

6464
bool is_equal_approx(const AABB &p_aabb) const;
65+
bool is_same(const AABB &p_aabb) const;
6566
bool is_finite() const;
6667
_FORCE_INLINE_ bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap
6768
_FORCE_INLINE_ bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap

core/math/basis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ bool Basis::is_equal_approx(const Basis &p_basis) const {
699699
return rows[0].is_equal_approx(p_basis.rows[0]) && rows[1].is_equal_approx(p_basis.rows[1]) && rows[2].is_equal_approx(p_basis.rows[2]);
700700
}
701701

702+
bool Basis::is_same(const Basis &p_basis) const {
703+
return rows[0].is_same(p_basis.rows[0]) && rows[1].is_same(p_basis.rows[1]) && rows[2].is_same(p_basis.rows[2]);
704+
}
705+
702706
bool Basis::is_finite() const {
703707
return rows[0].is_finite() && rows[1].is_finite() && rows[2].is_finite();
704708
}

core/math/basis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct [[nodiscard]] Basis {
120120
}
121121

122122
bool is_equal_approx(const Basis &p_basis) const;
123+
bool is_same(const Basis &p_basis) const;
123124
bool is_finite() const;
124125

125126
bool operator==(const Basis &p_matrix) const;

core/math/color.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ bool Color::is_equal_approx(const Color &p_color) const {
259259
return Math::is_equal_approx(r, p_color.r) && Math::is_equal_approx(g, p_color.g) && Math::is_equal_approx(b, p_color.b) && Math::is_equal_approx(a, p_color.a);
260260
}
261261

262+
bool Color::is_same(const Color &p_color) const {
263+
return Math::is_same(r, p_color.r) && Math::is_same(g, p_color.g) && Math::is_same(b, p_color.b) && Math::is_same(a, p_color.a);
264+
}
265+
262266
Color Color::clamp(const Color &p_min, const Color &p_max) const {
263267
return Color(
264268
CLAMP(r, p_min.r, p_max.r),

core/math/color.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct [[nodiscard]] Color {
9393
void operator/=(float p_scalar);
9494

9595
bool is_equal_approx(const Color &p_color) const;
96+
bool is_same(const Color &p_color) const;
9697

9798
Color clamp(const Color &p_min = Color(0, 0, 0, 0), const Color &p_max = Color(1, 1, 1, 1)) const;
9899
void invert();

core/math/math_funcs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ class Math {
593593
return abs(s) < (float)CMP_EPSILON;
594594
}
595595

596+
static _ALWAYS_INLINE_ bool is_same(float a, float b) {
597+
return (a == b) || (is_nan(a) && is_nan(b));
598+
}
599+
596600
static _ALWAYS_INLINE_ bool is_equal_approx(double a, double b) {
597601
// Check for exact equality first, required to handle "infinity" values.
598602
if (a == b) {
@@ -619,6 +623,10 @@ class Math {
619623
return abs(s) < CMP_EPSILON;
620624
}
621625

626+
static _ALWAYS_INLINE_ bool is_same(double a, double b) {
627+
return (a == b) || (is_nan(a) && is_nan(b));
628+
}
629+
622630
static _ALWAYS_INLINE_ float absf(float g) {
623631
union {
624632
float f;

core/math/plane.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ bool Plane::is_equal_approx(const Plane &p_plane) const {
172172
return normal.is_equal_approx(p_plane.normal) && Math::is_equal_approx(d, p_plane.d);
173173
}
174174

175+
bool Plane::is_same(const Plane &p_plane) const {
176+
return normal.is_same(p_plane.normal) && Math::is_same(d, p_plane.d);
177+
}
178+
175179
bool Plane::is_finite() const {
176180
return normal.is_finite() && Math::is_finite(d);
177181
}

core/math/plane.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct [[nodiscard]] Plane {
7272

7373
Plane operator-() const { return Plane(-normal, -d); }
7474
bool is_equal_approx(const Plane &p_plane) const;
75+
bool is_same(const Plane &p_plane) const;
7576
bool is_equal_approx_any_side(const Plane &p_plane) const;
7677
bool is_finite() const;
7778

core/math/projection.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,10 @@ void Projection::flip_y() {
780780
}
781781
}
782782

783+
bool Projection::is_same(const Projection &p_cam) const {
784+
return columns[0].is_same(p_cam.columns[0]) && columns[1].is_same(p_cam.columns[1]) && columns[2].is_same(p_cam.columns[2]) && columns[3].is_same(p_cam.columns[3]);
785+
}
786+
783787
Projection::Projection() {
784788
set_identity();
785789
}

0 commit comments

Comments
 (0)