Skip to content

Commit de94461

Browse files
authored
Merge pull request #58488 from lawnjelly/float_literals_casts
2 parents 9458a8f + 1485924 commit de94461

16 files changed

+69
-69
lines changed

core/math/basis.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
3838

3939
void Basis::from_z(const Vector3 &p_z) {
40-
if (Math::abs(p_z.z) > Math_SQRT12) {
40+
if (Math::abs(p_z.z) > (real_t)Math_SQRT12) {
4141
// choose p in y-z plane
4242
real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2];
4343
real_t k = 1.0f / Math::sqrt(a);
@@ -153,7 +153,7 @@ Basis Basis::diagonalize() {
153153

154154
int ite = 0;
155155
Basis acc_rot;
156-
while (off_matrix_norm_2 > CMP_EPSILON2 && ite++ < ite_max) {
156+
while (off_matrix_norm_2 > (real_t)CMP_EPSILON2 && ite++ < ite_max) {
157157
real_t el01_2 = elements[0][1] * elements[0][1];
158158
real_t el02_2 = elements[0][2] * elements[0][2];
159159
real_t el12_2 = elements[1][2] * elements[1][2];
@@ -463,8 +463,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {
463463

464464
Vector3 euler;
465465
real_t sy = elements[0][2];
466-
if (sy < (1.0f - CMP_EPSILON)) {
467-
if (sy > -(1.0f - CMP_EPSILON)) {
466+
if (sy < (1.0f - (real_t)CMP_EPSILON)) {
467+
if (sy > -(1.0f - (real_t)CMP_EPSILON)) {
468468
// is this a pure Y rotation?
469469
if (elements[1][0] == 0 && elements[0][1] == 0 && elements[1][2] == 0 && elements[2][1] == 0 && elements[1][1] == 1) {
470470
// return the simplest form (human friendlier in editor and scripts)
@@ -498,8 +498,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {
498498

499499
Vector3 euler;
500500
real_t sz = elements[0][1];
501-
if (sz < (1.0f - CMP_EPSILON)) {
502-
if (sz > -(1.0f - CMP_EPSILON)) {
501+
if (sz < (1.0f - (real_t)CMP_EPSILON)) {
502+
if (sz > -(1.0f - (real_t)CMP_EPSILON)) {
503503
euler.x = Math::atan2(elements[2][1], elements[1][1]);
504504
euler.y = Math::atan2(elements[0][2], elements[0][0]);
505505
euler.z = Math::asin(-sz);
@@ -529,8 +529,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {
529529

530530
real_t m12 = elements[1][2];
531531

532-
if (m12 < (1 - CMP_EPSILON)) {
533-
if (m12 > -(1 - CMP_EPSILON)) {
532+
if (m12 < (1 - (real_t)CMP_EPSILON)) {
533+
if (m12 > -(1 - (real_t)CMP_EPSILON)) {
534534
// is this a pure X rotation?
535535
if (elements[1][0] == 0 && elements[0][1] == 0 && elements[0][2] == 0 && elements[2][0] == 0 && elements[0][0] == 1) {
536536
// return the simplest form (human friendlier in editor and scripts)
@@ -565,8 +565,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {
565565

566566
Vector3 euler;
567567
real_t sz = elements[1][0];
568-
if (sz < (1.0f - CMP_EPSILON)) {
569-
if (sz > -(1.0f - CMP_EPSILON)) {
568+
if (sz < (1.0f - (real_t)CMP_EPSILON)) {
569+
if (sz > -(1.0f - (real_t)CMP_EPSILON)) {
570570
euler.x = Math::atan2(-elements[1][2], elements[1][1]);
571571
euler.y = Math::atan2(-elements[2][0], elements[0][0]);
572572
euler.z = Math::asin(sz);
@@ -593,8 +593,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {
593593
// -cx*sy sx cx*cy
594594
Vector3 euler;
595595
real_t sx = elements[2][1];
596-
if (sx < (1.0f - CMP_EPSILON)) {
597-
if (sx > -(1.0f - CMP_EPSILON)) {
596+
if (sx < (1.0f - (real_t)CMP_EPSILON)) {
597+
if (sx > -(1.0f - (real_t)CMP_EPSILON)) {
598598
euler.x = Math::asin(sx);
599599
euler.y = Math::atan2(-elements[2][0], elements[2][2]);
600600
euler.z = Math::atan2(-elements[0][1], elements[1][1]);
@@ -621,8 +621,8 @@ Vector3 Basis::get_euler(EulerOrder p_order) const {
621621
// -sy cy*sx cy*cx
622622
Vector3 euler;
623623
real_t sy = elements[2][0];
624-
if (sy < (1.0f - CMP_EPSILON)) {
625-
if (sy > -(1.0f - CMP_EPSILON)) {
624+
if (sy < (1.0f - (real_t)CMP_EPSILON)) {
625+
if (sy > -(1.0f - (real_t)CMP_EPSILON)) {
626626
euler.x = Math::atan2(elements[2][1], elements[2][2]);
627627
euler.y = Math::asin(-sy);
628628
euler.z = Math::atan2(elements[1][0], elements[0][0]);

core/math/color.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct _NO_DISCARD_ Color {
138138

139139
float cMax = MAX(cRed, MAX(cGreen, cBlue));
140140

141-
float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / Math_LN2)) + 1.0f + B;
141+
float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / (real_t)Math_LN2)) + 1.0f + B;
142142

143143
float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f);
144144

core/math/face3.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
4242
int below_count = 0;
4343

4444
for (int i = 0; i < 3; i++) {
45-
if (p_plane.has_point(vertex[i], CMP_EPSILON)) { // point is in plane
45+
if (p_plane.has_point(vertex[i], (real_t)CMP_EPSILON)) { // point is in plane
4646

4747
ERR_FAIL_COND_V(above_count >= 4, 0);
4848
above[above_count++] = vertex[i];
@@ -117,7 +117,7 @@ bool Face3::intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vect
117117

118118
bool Face3::is_degenerate() const {
119119
Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]);
120-
return (normal.length_squared() < CMP_EPSILON2);
120+
return (normal.length_squared() < (real_t)CMP_EPSILON2);
121121
}
122122

123123
Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) const {

core/math/geometry_2d.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ Vector<Vector<Point2>> Geometry2D::_polypaths_do_operation(PolyBooleanOperation
218218

219219
// Need to scale points (Clipper's requirement for robust computation).
220220
for (int i = 0; i != p_polypath_a.size(); ++i) {
221-
path_a << IntPoint(p_polypath_a[i].x * SCALE_FACTOR, p_polypath_a[i].y * SCALE_FACTOR);
221+
path_a << IntPoint(p_polypath_a[i].x * (real_t)SCALE_FACTOR, p_polypath_a[i].y * (real_t)SCALE_FACTOR);
222222
}
223223
for (int i = 0; i != p_polypath_b.size(); ++i) {
224-
path_b << IntPoint(p_polypath_b[i].x * SCALE_FACTOR, p_polypath_b[i].y * SCALE_FACTOR);
224+
path_b << IntPoint(p_polypath_b[i].x * (real_t)SCALE_FACTOR, p_polypath_b[i].y * (real_t)SCALE_FACTOR);
225225
}
226226
Clipper clp;
227227
clp.AddPath(path_a, ptSubject, !is_a_open); // Forward compatible with Clipper 10.0.0.
@@ -246,8 +246,8 @@ Vector<Vector<Point2>> Geometry2D::_polypaths_do_operation(PolyBooleanOperation
246246

247247
for (Paths::size_type j = 0; j < scaled_path.size(); ++j) {
248248
polypath.push_back(Point2(
249-
static_cast<real_t>(scaled_path[j].X) / SCALE_FACTOR,
250-
static_cast<real_t>(scaled_path[j].Y) / SCALE_FACTOR));
249+
static_cast<real_t>(scaled_path[j].X) / (real_t)SCALE_FACTOR,
250+
static_cast<real_t>(scaled_path[j].Y) / (real_t)SCALE_FACTOR));
251251
}
252252
polypaths.push_back(polypath);
253253
}
@@ -290,17 +290,17 @@ Vector<Vector<Point2>> Geometry2D::_polypath_offset(const Vector<Point2> &p_poly
290290
et = etOpenRound;
291291
break;
292292
}
293-
ClipperOffset co(2.0, 0.25f * SCALE_FACTOR); // Defaults from ClipperOffset.
293+
ClipperOffset co(2.0, 0.25f * (real_t)SCALE_FACTOR); // Defaults from ClipperOffset.
294294
Path path;
295295

296296
// Need to scale points (Clipper's requirement for robust computation).
297297
for (int i = 0; i != p_polypath.size(); ++i) {
298-
path << IntPoint(p_polypath[i].x * SCALE_FACTOR, p_polypath[i].y * SCALE_FACTOR);
298+
path << IntPoint(p_polypath[i].x * (real_t)SCALE_FACTOR, p_polypath[i].y * (real_t)SCALE_FACTOR);
299299
}
300300
co.AddPath(path, jt, et);
301301

302302
Paths paths;
303-
co.Execute(paths, p_delta * SCALE_FACTOR); // Inflate/deflate.
303+
co.Execute(paths, p_delta * (real_t)SCALE_FACTOR); // Inflate/deflate.
304304

305305
// Have to scale points down now.
306306
Vector<Vector<Point2>> polypaths;
@@ -312,8 +312,8 @@ Vector<Vector<Point2>> Geometry2D::_polypath_offset(const Vector<Point2> &p_poly
312312

313313
for (Paths::size_type j = 0; j < scaled_path.size(); ++j) {
314314
polypath.push_back(Point2(
315-
static_cast<real_t>(scaled_path[j].X) / SCALE_FACTOR,
316-
static_cast<real_t>(scaled_path[j].Y) / SCALE_FACTOR));
315+
static_cast<real_t>(scaled_path[j].X) / (real_t)SCALE_FACTOR,
316+
static_cast<real_t>(scaled_path[j].Y) / (real_t)SCALE_FACTOR));
317317
}
318318
polypaths.push_back(polypath);
319319
}

core/math/geometry_2d.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ class Geometry2D {
5151
real_t f = d2.dot(r);
5252
real_t s, t;
5353
// Check if either or both segments degenerate into points.
54-
if (a <= CMP_EPSILON && e <= CMP_EPSILON) {
54+
if (a <= (real_t)CMP_EPSILON && e <= (real_t)CMP_EPSILON) {
5555
// Both segments degenerate into points.
5656
c1 = p1;
5757
c2 = p2;
5858
return Math::sqrt((c1 - c2).dot(c1 - c2));
5959
}
60-
if (a <= CMP_EPSILON) {
60+
if (a <= (real_t)CMP_EPSILON) {
6161
// First segment degenerates into a point.
6262
s = 0.0;
6363
t = f / e; // s = 0 => t = (b*s + f) / e = f / e
6464
t = CLAMP(t, 0.0f, 1.0f);
6565
} else {
6666
real_t c = d1.dot(r);
67-
if (e <= CMP_EPSILON) {
67+
if (e <= (real_t)CMP_EPSILON) {
6868
// Second segment degenerates into a point.
6969
t = 0.0;
7070
s = CLAMP(-c / a, 0.0f, 1.0f); // t = 0 => s = (b*t - c) / a = -c / a
@@ -185,7 +185,7 @@ class Geometry2D {
185185
D = Vector2(D.x * Bn.x + D.y * Bn.y, D.y * Bn.x - D.x * Bn.y);
186186

187187
// Fail if C x B and D x B have the same sign (segments don't intersect).
188-
if ((C.y < -CMP_EPSILON && D.y < -CMP_EPSILON) || (C.y > CMP_EPSILON && D.y > CMP_EPSILON)) {
188+
if ((C.y < (real_t)-CMP_EPSILON && D.y < (real_t)-CMP_EPSILON) || (C.y > (real_t)CMP_EPSILON && D.y > (real_t)CMP_EPSILON)) {
189189
return false;
190190
}
191191

@@ -198,7 +198,7 @@ class Geometry2D {
198198
real_t ABpos = D.x + (C.x - D.x) * D.y / (D.y - C.y);
199199

200200
// Fail if segment C-D crosses line A-B outside of segment A-B.
201-
if (ABpos < 0 || ABpos > 1.0f) {
201+
if ((ABpos < 0) || (ABpos > 1)) {
202202
return false;
203203
}
204204

core/math/geometry_3d.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ Vector<Vector3> Geometry3D::compute_convex_mesh_points(const Plane *p_planes, in
879879
for (int n = 0; n < p_plane_count; n++) {
880880
if (n != i && n != j && n != k) {
881881
real_t dp = p_planes[n].normal.dot(convex_shape_point);
882-
if (dp - p_planes[n].d > CMP_EPSILON) {
882+
if (dp - p_planes[n].d > (real_t)CMP_EPSILON) {
883883
excluded = true;
884884
break;
885885
}

core/math/geometry_3d.h

+15-15
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Geometry3D {
7676
real_t tc, tN, tD = D; // tc = tN / tD, default tD = D >= 0
7777

7878
// Compute the line parameters of the two closest points.
79-
if (D < CMP_EPSILON) { // The lines are almost parallel.
79+
if (D < (real_t)CMP_EPSILON) { // The lines are almost parallel.
8080
sN = 0.0f; // Force using point P0 on segment S1
8181
sD = 1.0f; // to prevent possible division by 0.0 later.
8282
tN = e;
@@ -142,15 +142,15 @@ class Geometry3D {
142142
Vector3 s = p_from - p_v0;
143143
real_t u = f * s.dot(h);
144144

145-
if (u < 0.0f || u > 1.0f) {
145+
if ((u < 0.0f) || (u > 1.0f)) {
146146
return false;
147147
}
148148

149149
Vector3 q = s.cross(e1);
150150

151151
real_t v = f * p_dir.dot(q);
152152

153-
if (v < 0.0f || u + v > 1.0f) {
153+
if ((v < 0.0f) || (u + v > 1.0f)) {
154154
return false;
155155
}
156156

@@ -183,23 +183,23 @@ class Geometry3D {
183183
Vector3 s = p_from - p_v0;
184184
real_t u = f * s.dot(h);
185185

186-
if (u < 0.0f || u > 1.0f) {
186+
if ((u < 0.0f) || (u > 1.0f)) {
187187
return false;
188188
}
189189

190190
Vector3 q = s.cross(e1);
191191

192192
real_t v = f * rel.dot(q);
193193

194-
if (v < 0.0f || u + v > 1.0f) {
194+
if ((v < 0.0f) || (u + v > 1.0f)) {
195195
return false;
196196
}
197197

198198
// At this stage we can compute t to find out where
199199
// the intersection point is on the line.
200200
real_t t = f * e2.dot(q);
201201

202-
if (t > CMP_EPSILON && t <= 1.0f) { // Ray intersection.
202+
if (t > (real_t)CMP_EPSILON && t <= 1.0f) { // Ray intersection.
203203
if (r_res) {
204204
*r_res = p_from + rel * t;
205205
}
@@ -213,7 +213,7 @@ class Geometry3D {
213213
Vector3 sphere_pos = p_sphere_pos - p_from;
214214
Vector3 rel = (p_to - p_from);
215215
real_t rel_l = rel.length();
216-
if (rel_l < CMP_EPSILON) {
216+
if (rel_l < (real_t)CMP_EPSILON) {
217217
return false; // Both points are the same.
218218
}
219219
Vector3 normal = rel / rel_l;
@@ -229,7 +229,7 @@ class Geometry3D {
229229
real_t inters_d2 = p_sphere_radius * p_sphere_radius - ray_distance * ray_distance;
230230
real_t inters_d = sphere_d;
231231

232-
if (inters_d2 >= CMP_EPSILON) {
232+
if (inters_d2 >= (real_t)CMP_EPSILON) {
233233
inters_d -= Math::sqrt(inters_d2);
234234
}
235235

@@ -253,7 +253,7 @@ class Geometry3D {
253253
static inline bool segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, real_t p_height, real_t p_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr, int p_cylinder_axis = 2) {
254254
Vector3 rel = (p_to - p_from);
255255
real_t rel_l = rel.length();
256-
if (rel_l < CMP_EPSILON) {
256+
if (rel_l < (real_t)CMP_EPSILON) {
257257
return false; // Both points are the same.
258258
}
259259

@@ -269,7 +269,7 @@ class Geometry3D {
269269

270270
Vector3 axis_dir;
271271

272-
if (crs_l < CMP_EPSILON) {
272+
if (crs_l < (real_t)CMP_EPSILON) {
273273
Vector3 side_axis;
274274
side_axis[(p_cylinder_axis + 1) % 3] = 1.0f; // Any side axis OK.
275275
axis_dir = side_axis;
@@ -285,7 +285,7 @@ class Geometry3D {
285285

286286
// Convert to 2D.
287287
real_t w2 = p_radius * p_radius - dist * dist;
288-
if (w2 < CMP_EPSILON) {
288+
if (w2 < (real_t)CMP_EPSILON) {
289289
return false; // Avoid numerical error.
290290
}
291291
Size2 size(Math::sqrt(w2), p_height * 0.5f);
@@ -366,7 +366,7 @@ class Geometry3D {
366366
Vector3 rel = p_to - p_from;
367367
real_t rel_l = rel.length();
368368

369-
if (rel_l < CMP_EPSILON) {
369+
if (rel_l < (real_t)CMP_EPSILON) {
370370
return false;
371371
}
372372

@@ -379,7 +379,7 @@ class Geometry3D {
379379

380380
real_t den = p.normal.dot(dir);
381381

382-
if (Math::abs(den) <= CMP_EPSILON) {
382+
if (Math::abs(den) <= (real_t)CMP_EPSILON) {
383383
continue; // Ignore parallel plane.
384384
}
385385

@@ -564,11 +564,11 @@ class Geometry3D {
564564

565565
for (int a = 0; a < polygon.size(); a++) {
566566
real_t dist = p_plane.distance_to(polygon[a]);
567-
if (dist < -CMP_POINT_IN_PLANE_EPSILON) {
567+
if (dist < (real_t)-CMP_POINT_IN_PLANE_EPSILON) {
568568
location_cache[a] = LOC_INSIDE;
569569
inside_count++;
570570
} else {
571-
if (dist > CMP_POINT_IN_PLANE_EPSILON) {
571+
if (dist > (real_t)CMP_POINT_IN_PLANE_EPSILON) {
572572
location_cache[a] = LOC_OUTSIDE;
573573
outside_count++;
574574
} else {

0 commit comments

Comments
 (0)