Skip to content

Commit f57d7e6

Browse files
committed
Use float literals and real_t consistently around square values
1 parent 28bd72a commit f57d7e6

14 files changed

+36
-36
lines changed

editor/scene/2d/sprite_2d_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Vector<Vector2> expand(const Vector<Vector2> &points, const Rect2i &rect, float
9090
Vector2 prev = Vector2(p2[lasti].x, p2[lasti].y);
9191
for (uint64_t i = 0; i < p2.size(); i++) {
9292
Vector2 cur = Vector2(p2[i].x, p2[i].y);
93-
if (cur.distance_to(prev) > 0.5) {
93+
if (cur.distance_to(prev) > 0.5f) {
9494
outPoints.push_back(cur);
9595
prev = cur;
9696
}

editor/scene/2d/tiles/tile_data_editors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@ void GenericTilePolygonEditor::_grab_polygon_point(Vector2 p_pos, const Transfor
414414
const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
415415
r_polygon_index = -1;
416416
r_point_index = -1;
417-
float closest_distance = grab_threshold + 1.0;
417+
real_t closest_distance = grab_threshold + 1.0f;
418418
for (unsigned int i = 0; i < polygons.size(); i++) {
419419
const Vector<Vector2> &polygon = polygons[i];
420420
for (int j = 0; j < polygon.size(); j++) {
421-
float distance = p_pos.distance_to(p_polygon_xform.xform(polygon[j]));
421+
const real_t distance = p_pos.distance_to(p_polygon_xform.xform(polygon[j]));
422422
if (distance < grab_threshold && distance < closest_distance) {
423423
r_polygon_index = i;
424424
r_point_index = j;

editor/scene/3d/node_3d_editor_plugin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ void ViewportRotationControl::_draw_axis(const Axis2D &p_axis) {
353353
// Draw axis lines for the positive axes.
354354
const Vector2 center = get_size() / 2.0;
355355
const Vector2 diff = p_axis.screen_point - center;
356-
const float line_length = MAX(diff.length() - AXIS_CIRCLE_RADIUS - 0.5 * EDSCALE, 0);
356+
const real_t line_length = MAX(diff.length() - (AXIS_CIRCLE_RADIUS + 0.5f * EDSCALE), 0);
357357

358-
draw_line(center + diff.limit_length(0.5 * EDSCALE), center + diff.limit_length(line_length), c, 1.5 * EDSCALE, true);
358+
draw_line(center + diff.limit_length(0.5f * EDSCALE), center + diff.limit_length(line_length), c, 1.5f * EDSCALE, true);
359359

360360
draw_circle(p_axis.screen_point, AXIS_CIRCLE_RADIUS, c, true, -1.0, true);
361361

@@ -374,8 +374,8 @@ void ViewportRotationControl::_draw_axis(const Axis2D &p_axis) {
374374
}
375375

376376
void ViewportRotationControl::_get_sorted_axis(Vector<Axis2D> &r_axis) {
377-
const Vector2 center = get_size() / 2.0;
378-
const real_t radius = get_size().x / 2.0 - AXIS_CIRCLE_RADIUS - 2.0 * EDSCALE;
377+
const Vector2 center = get_size() / 2.0f;
378+
const real_t radius = get_size().x / 2.0f - (AXIS_CIRCLE_RADIUS + 2.0f * EDSCALE);
379379
const Basis camera_basis = viewport->to_camera_transform(viewport->cursor).get_basis().inverse();
380380

381381
for (int i = 0; i < 3; ++i) {

editor/scene/canvas_item_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) {
17991799
};
18001800

18011801
DragType resize_drag = DRAG_NONE;
1802-
real_t radius = (select_handle->get_size().width / 2) * 1.5;
1802+
const real_t radius = select_handle->get_size().width * (1.5f / 2.0f);
18031803

18041804
for (int i = 0; i < 4; i++) {
18051805
int prev = (i + 3) % 4;

modules/godot_physics_3d/godot_body_pair_3d.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ bool GodotBodyPair3D::_test_ccd(real_t p_step, GodotBody3D *p_A, int p_shape_A,
202202
shape_A_ptr->get_supports(p_xform_A.basis.xform_inv(mnormal).normalized(), max_supports, supports_A, support_count_A, support_type_A);
203203

204204
// Cast a segment from each support point of A in the motion direction.
205-
int segment_support_idx = -1;
206-
float segment_hit_length = FLT_MAX;
207205
Vector3 segment_hit_local;
206+
real_t segment_hit_length = FLT_MAX;
207+
int segment_support_idx = -1;
208208
for (int i = 0; i < support_count_A; i++) {
209209
supports_A[i] = p_xform_A.xform(supports_A[i]);
210210

@@ -222,7 +222,7 @@ bool GodotBodyPair3D::_test_ccd(real_t p_step, GodotBody3D *p_A, int p_shape_A,
222222
Vector3 rpos, rnorm;
223223
int fi = -1;
224224
if (p_B->get_shape(p_shape_B)->intersect_segment(local_from, local_to, rpos, rnorm, fi, true)) {
225-
float hit_length = local_from.distance_to(rpos);
225+
const real_t hit_length = local_from.distance_to(rpos);
226226
if (hit_length < segment_hit_length) {
227227
segment_support_idx = i;
228228
segment_hit_length = hit_length;

modules/mobile_vr/mobile_vr_interface.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,27 @@ void MobileVRInterface::set_position_from_sensors() {
146146
if (sensor_first) {
147147
sensor_first = false;
148148
} else {
149-
acc = scrub(acc, last_accerometer_data, 2, 0.2);
150-
magneto = scrub(magneto, last_magnetometer_data, 3, 0.3);
149+
acc = scrub(acc, last_accerometer_data, 2, 0.2f);
150+
magneto = scrub(magneto, last_magnetometer_data, 3, 0.3f);
151151
};
152152

153153
last_accerometer_data = acc;
154154
last_magnetometer_data = magneto;
155155

156-
if (grav.length() < 0.1) {
156+
if (grav.length() < 0.1f) {
157157
// not ideal but use our accelerometer, this will contain shaky user behavior
158158
// maybe look into some math but I'm guessing that if this isn't available, it's because we lack the gyro sensor to actually work out
159159
// what a stable gravity vector is
160160
grav = acc;
161-
if (grav.length() > 0.1) {
161+
if (grav.length() > 0.1f) {
162162
has_grav = true;
163163
};
164164
} else {
165165
has_grav = true;
166166
};
167167

168-
bool has_magneto = magneto.length() > 0.1;
169-
if (gyro.length() > 0.1) {
168+
const bool has_magneto = magneto.length() > 0.1f;
169+
if (gyro.length() > 0.1f) {
170170
/* this can return to 0.0 if the user doesn't move the phone, so once on, it's on */
171171
has_gyro = true;
172172
};

scene/2d/cpu_particles_2d.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,14 +1000,14 @@ void CPUParticles2D::_particles_process(double p_delta) {
10001000
Vector2 pos = p.transform[2];
10011001

10021002
//apply linear acceleration
1003-
force += p.velocity.length() > 0.0 ? p.velocity.normalized() * tex_linear_accel * Math::lerp(parameters_min[PARAM_LINEAR_ACCEL], parameters_max[PARAM_LINEAR_ACCEL], rand_from_seed(_seed)) : Vector2();
1003+
force += p.velocity.length_squared() > 0.0f ? p.velocity.normalized() * tex_linear_accel * Math::lerp(parameters_min[PARAM_LINEAR_ACCEL], parameters_max[PARAM_LINEAR_ACCEL], rand_from_seed(_seed)) : Vector2();
10041004
//apply radial acceleration
10051005
Vector2 org = emission_xform[2];
10061006
Vector2 diff = pos - org;
1007-
force += diff.length() > 0.0 ? diff.normalized() * (tex_radial_accel)*Math::lerp(parameters_min[PARAM_RADIAL_ACCEL], parameters_max[PARAM_RADIAL_ACCEL], rand_from_seed(_seed)) : Vector2();
1007+
force += diff.length_squared() > 0.0f ? diff.normalized() * (tex_radial_accel)*Math::lerp(parameters_min[PARAM_RADIAL_ACCEL], parameters_max[PARAM_RADIAL_ACCEL], rand_from_seed(_seed)) : Vector2();
10081008
//apply tangential acceleration;
10091009
Vector2 yx = Vector2(diff.y, diff.x);
1010-
force += yx.length() > 0.0 ? (yx * Vector2(-1.0, 1.0)).normalized() * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(_seed))) : Vector2();
1010+
force += yx.length_squared() > 0.0f ? (yx * Vector2(-1.0, 1.0)).normalized() * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(_seed))) : Vector2();
10111011
//apply attractor forces
10121012
p.velocity += force * local_delta;
10131013
//orbit velocity
@@ -1096,7 +1096,7 @@ void CPUParticles2D::_particles_process(double p_delta) {
10961096
p.color *= p.base_color * p.start_color_rand;
10971097

10981098
if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
1099-
if (p.velocity.length() > 0.0) {
1099+
if (p.velocity.length_squared() > 0.0f) {
11001100
p.transform.columns[1] = p.velocity;
11011101
}
11021102

scene/2d/physics/character_body_2d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
153153
// If we hit a ceiling platform, we set the vertical velocity to at least the platform one.
154154
if (on_ceiling && result.collider_velocity != Vector2() && result.collider_velocity.dot(up_direction) < 0) {
155155
// If ceiling sliding is on, only apply when the ceiling is flat or when the motion is upward.
156-
if (!slide_on_ceiling || motion.dot(up_direction) < 0 || (result.collision_normal + up_direction).length() < 0.01) {
156+
if (!slide_on_ceiling || motion.dot(up_direction) < 0 || (result.collision_normal + up_direction).length() < 0.01f) {
157157
apply_ceiling_velocity = true;
158158
Vector2 ceiling_vertical_velocity = up_direction * up_direction.dot(result.collider_velocity);
159159
Vector2 motion_vertical_velocity = up_direction * up_direction.dot(velocity);
@@ -163,7 +163,7 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
163163
}
164164
}
165165

166-
if (on_floor && floor_stop_on_slope && (velocity.normalized() + up_direction).length() < 0.01) {
166+
if (on_floor && floor_stop_on_slope && (velocity.normalized() + up_direction).length() < 0.01f) {
167167
Transform2D gt = get_global_transform();
168168
if (result.travel.length() <= margin + CMP_EPSILON) {
169169
gt.columns[2] -= result.travel;

scene/3d/cpu_particles_3d.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,19 +1044,19 @@ void CPUParticles3D::_particles_process(double p_delta) {
10441044
position.z = 0.0;
10451045
}
10461046
//apply linear acceleration
1047-
force += p.velocity.length() > 0.0 ? p.velocity.normalized() * tex_linear_accel * Math::lerp(parameters_min[PARAM_LINEAR_ACCEL], parameters_max[PARAM_LINEAR_ACCEL], rand_from_seed(alt_seed)) : Vector3();
1047+
force += p.velocity.length_squared() > 0.0f ? p.velocity.normalized() * tex_linear_accel * Math::lerp(parameters_min[PARAM_LINEAR_ACCEL], parameters_max[PARAM_LINEAR_ACCEL], rand_from_seed(alt_seed)) : Vector3();
10481048
//apply radial acceleration
10491049
Vector3 org = emission_xform.origin;
10501050
Vector3 diff = position - org;
1051-
force += diff.length() > 0.0 ? diff.normalized() * (tex_radial_accel)*Math::lerp(parameters_min[PARAM_RADIAL_ACCEL], parameters_max[PARAM_RADIAL_ACCEL], rand_from_seed(alt_seed)) : Vector3();
1051+
force += diff.length_squared() > 0.0f ? diff.normalized() * (tex_radial_accel)*Math::lerp(parameters_min[PARAM_RADIAL_ACCEL], parameters_max[PARAM_RADIAL_ACCEL], rand_from_seed(alt_seed)) : Vector3();
10521052
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
10531053
Vector2 yx = Vector2(diff.y, diff.x);
10541054
Vector2 yx2 = (yx * Vector2(-1.0, 1.0)).normalized();
1055-
force += yx.length() > 0.0 ? Vector3(yx2.x, yx2.y, 0.0) * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(alt_seed))) : Vector3();
1055+
force += yx.length_squared() > 0.0f ? Vector3(yx2.x, yx2.y, 0.0) * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(alt_seed))) : Vector3();
10561056

10571057
} else {
10581058
Vector3 crossDiff = diff.normalized().cross(gravity.normalized());
1059-
force += crossDiff.length() > 0.0 ? crossDiff.normalized() * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(alt_seed))) : Vector3();
1059+
force += crossDiff.length_squared() > 0.0f ? crossDiff.normalized() * (tex_tangential_accel * Math::lerp(parameters_min[PARAM_TANGENTIAL_ACCEL], parameters_max[PARAM_TANGENTIAL_ACCEL], rand_from_seed(alt_seed))) : Vector3();
10601060
}
10611061
//apply attractor forces
10621062
p.velocity += force * local_delta;
@@ -1156,7 +1156,7 @@ void CPUParticles3D::_particles_process(double p_delta) {
11561156

11571157
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
11581158
if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
1159-
if (p.velocity.length() > 0.0) {
1159+
if (p.velocity.length_squared() > 0.0f) {
11601160
p.transform.basis.set_column(1, p.velocity.normalized());
11611161
} else {
11621162
p.transform.basis.set_column(1, p.transform.basis.get_column(1));
@@ -1173,7 +1173,7 @@ void CPUParticles3D::_particles_process(double p_delta) {
11731173
} else {
11741174
//orient particle Y towards velocity
11751175
if (particle_flags[PARTICLE_FLAG_ALIGN_Y_TO_VELOCITY]) {
1176-
if (p.velocity.length() > 0.0) {
1176+
if (p.velocity.length_squared() > 0.0f) {
11771177
p.transform.basis.set_column(1, p.velocity.normalized());
11781178
} else {
11791179
p.transform.basis.set_column(1, p.transform.basis.get_column(1).normalized());

scene/3d/gpu_particles_collision_3d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void GPUParticlesCollisionSDF3D::_find_closest_distance(const Vector3 &p_pos, co
326326
bool pass = true;
327327
if (!p_bvh[p_bvh_cell].bounds.has_point(p_pos)) {
328328
//outside, find closest point
329-
Vector3 he = p_bvh[p_bvh_cell].bounds.size * 0.5;
329+
const Vector3 he = p_bvh[p_bvh_cell].bounds.size * 0.5f;
330330
Vector3 center = p_bvh[p_bvh_cell].bounds.position + he;
331331

332332
Vector3 rel = (p_pos - center).abs();

0 commit comments

Comments
 (0)