Skip to content

Commit 021b5a4

Browse files
committed
Merge pull request #69406 from KoBeWi/The_Assassination_of_ABS_by_the_Math--abs
Remove `ABS` in favor of `Math::abs`
2 parents 2776d32 + 10f6c01 commit 021b5a4

File tree

68 files changed

+142
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+142
-146
lines changed

core/io/image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ Image::Format Image::get_format() const {
799799
}
800800

801801
static double _bicubic_interp_kernel(double x) {
802-
x = ABS(x);
802+
x = Math::abs(x);
803803

804804
double bc = 0;
805805

core/math/a_star_grid_2d.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@
3434
#include "core/variant/typed_array.h"
3535

3636
static real_t heuristic_euclidean(const Vector2i &p_from, const Vector2i &p_to) {
37-
real_t dx = (real_t)ABS(p_to.x - p_from.x);
38-
real_t dy = (real_t)ABS(p_to.y - p_from.y);
37+
real_t dx = (real_t)Math::abs(p_to.x - p_from.x);
38+
real_t dy = (real_t)Math::abs(p_to.y - p_from.y);
3939
return (real_t)Math::sqrt(dx * dx + dy * dy);
4040
}
4141

4242
static real_t heuristic_manhattan(const Vector2i &p_from, const Vector2i &p_to) {
43-
real_t dx = (real_t)ABS(p_to.x - p_from.x);
44-
real_t dy = (real_t)ABS(p_to.y - p_from.y);
43+
real_t dx = (real_t)Math::abs(p_to.x - p_from.x);
44+
real_t dy = (real_t)Math::abs(p_to.y - p_from.y);
4545
return dx + dy;
4646
}
4747

4848
static real_t heuristic_octile(const Vector2i &p_from, const Vector2i &p_to) {
49-
real_t dx = (real_t)ABS(p_to.x - p_from.x);
50-
real_t dy = (real_t)ABS(p_to.y - p_from.y);
49+
real_t dx = (real_t)Math::abs(p_to.x - p_from.x);
50+
real_t dy = (real_t)Math::abs(p_to.y - p_from.y);
5151
real_t F = Math_SQRT2 - 1;
5252
return (dx < dy) ? F * dx + dy : F * dy + dx;
5353
}
5454

5555
static real_t heuristic_chebyshev(const Vector2i &p_from, const Vector2i &p_to) {
56-
real_t dx = (real_t)ABS(p_to.x - p_from.x);
57-
real_t dy = (real_t)ABS(p_to.y - p_from.y);
56+
real_t dx = (real_t)Math::abs(p_to.x - p_from.x);
57+
real_t dy = (real_t)Math::abs(p_to.y - p_from.y);
5858
return MAX(dx, dy);
5959
}
6060

core/math/delaunay_3d.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class Delaunay3D {
186186
Plane p(p_points[p_simplex.points[i]], p_points[p_simplex.points[(i + 1) % 4]], p_points[p_simplex.points[(i + 2) % 4]]);
187187
// This tolerance should not be smaller than the one used with
188188
// Plane::has_point() when creating the LightmapGI probe BSP tree.
189-
if (ABS(p.distance_to(p_points[p_simplex.points[(i + 3) % 4]])) < 0.001) {
189+
if (Math::abs(p.distance_to(p_points[p_simplex.points[(i + 3) % 4]])) < 0.001) {
190190
return true;
191191
}
192192
}

core/math/face3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform3D &p_transform,
263263

264264
// check if edge is valid as a support
265265
real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n);
266-
dot = ABS(dot);
266+
dot = Math::abs(dot);
267267
if (dot < edge_support_threshold) {
268268
*p_count = MIN(2, p_max);
269269

core/math/geometry_3d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes
593593

594594
Vector3 ref = Vector3(0.0, 1.0, 0.0);
595595

596-
if (ABS(p.normal.dot(ref)) > 0.95f) {
596+
if (Math::abs(p.normal.dot(ref)) > 0.95f) {
597597
ref = Vector3(0.0, 0.0, 1.0); // Change axis.
598598
}
599599

core/math/geometry_3d.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class Geometry3D {
419419

420420
real_t ad = axis.dot(n2);
421421

422-
if (ABS(ad) > p_sphere_radius) {
422+
if (Math::abs(ad) > p_sphere_radius) {
423423
// No chance with this edge, too far away.
424424
continue;
425425
}

core/math/math_funcs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ class Math {
221221

222222
static _ALWAYS_INLINE_ double abs(double g) { return absd(g); }
223223
static _ALWAYS_INLINE_ float abs(float g) { return absf(g); }
224-
static _ALWAYS_INLINE_ int abs(int g) { return g > 0 ? g : -g; }
224+
static _ALWAYS_INLINE_ int8_t abs(int8_t g) { return g > 0 ? g : -g; }
225+
static _ALWAYS_INLINE_ int16_t abs(int16_t g) { return g > 0 ? g : -g; }
226+
static _ALWAYS_INLINE_ int32_t abs(int32_t g) { return ::abs(g); }
227+
static _ALWAYS_INLINE_ int64_t abs(int64_t g) { return ::llabs(g); }
225228

226229
static _ALWAYS_INLINE_ double fposmod(double p_x, double p_y) {
227230
double value = Math::fmod(p_x, p_y);

core/math/plane.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Vector3 Plane::get_any_perpendicular_normal() const {
5858
static const Vector3 p2 = Vector3(0, 1, 0);
5959
Vector3 p;
6060

61-
if (ABS(normal.dot(p1)) > 0.99f) { // if too similar to p1
61+
if (Math::abs(normal.dot(p1)) > 0.99f) { // if too similar to p1
6262
p = p2; // use p2
6363
} else {
6464
p = p1; // use p1

core/math/plane.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ real_t Plane::distance_to(const Vector3 &p_point) const {
100100

101101
bool Plane::has_point(const Vector3 &p_point, real_t p_tolerance) const {
102102
real_t dist = normal.dot(p_point) - d;
103-
dist = ABS(dist);
103+
dist = Math::abs(dist);
104104
return (dist <= p_tolerance);
105105
}
106106

core/string/ustring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
17161716
c[chars] = 0;
17171717
n = p_num;
17181718
do {
1719-
int mod = ABS(n % base);
1719+
int mod = Math::abs(n % base);
17201720
if (mod >= 10) {
17211721
char a = (capitalize_hex ? 'A' : 'a');
17221722
c[--chars] = a + (mod - 10);
@@ -5593,7 +5593,7 @@ String String::sprintf(const Array &values, bool *error) const {
55935593
// Get basic number.
55945594
String str;
55955595
if (!as_unsigned) {
5596-
str = String::num_int64(ABS(value), base, capitalize);
5596+
str = String::num_int64(Math::abs(value), base, capitalize);
55975597
} else {
55985598
uint64_t uvalue = *((uint64_t *)&value);
55995599
// In unsigned hex, if the value fits in 32 bits, trim it down to that.

0 commit comments

Comments
 (0)