Skip to content

Commit 8d95db0

Browse files
committed
Use const and float literals (changes from squared values PR)
1 parent 42224bb commit 8d95db0

33 files changed

+129
-125
lines changed

editor/scene/2d/abstract_polygon_2d_editor.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
496496

497497
// Center drag.
498498
if (edit_origin_and_center) {
499-
real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
499+
const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
500500

501501
if (mb->get_button_index() == MouseButton::LEFT) {
502502
if (mb->is_meta_pressed() || mb->is_ctrl_pressed() || mb->is_shift_pressed() || mb->is_alt_pressed()) {
@@ -836,9 +836,9 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_point(const
836836
for (int i = 0; i < n_points; i++) {
837837
Vector2 cp = xform.xform(points[i] + offset);
838838

839-
real_t d = cp.distance_to(p_pos);
840-
if (d < closest_dist && d < grab_threshold) {
841-
closest_dist = d;
839+
const real_t dist = cp.distance_to(p_pos);
840+
if (dist < closest_dist && dist < grab_threshold) {
841+
closest_dist = dist;
842842
closest = PosVertex(j, i, cp);
843843
}
844844
}
@@ -874,9 +874,9 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_edge_point(c
874874
continue; //not valid to reuse point
875875
}
876876

877-
real_t d = cp.distance_to(p_pos);
878-
if (d < closest_dist && d < grab_threshold) {
879-
closest_dist = d;
877+
const real_t dist = cp.distance_to(p_pos);
878+
if (dist < closest_dist && dist < grab_threshold) {
879+
closest_dist = dist;
880880
closest = PosVertex(j, i, cp);
881881
}
882882
}

editor/scene/2d/path_2d_editor_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
7979
return false;
8080
}
8181

82-
real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
82+
const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
8383

8484
Ref<InputEventMouseButton> mb = p_event;
8585
if (mb.is_valid()) {

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: 3 additions & 3 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;
@@ -514,7 +514,7 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event)
514514
undo_redo = memnew(EditorUndoRedoManager);
515515
}
516516

517-
real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
517+
const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
518518

519519
hovered_polygon_index = -1;
520520
hovered_point_index = -1;

editor/scene/3d/node_3d_editor_plugin.cpp

Lines changed: 6 additions & 6 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) {
@@ -430,7 +430,7 @@ void ViewportRotationControl::_process_click(int p_index, Vector2 p_position, bo
430430

431431
void ViewportRotationControl::_process_drag(Ref<InputEventWithModifiers> p_event, int p_index, Vector2 p_position, Vector2 p_relative_position) {
432432
Point2 mouse_pos = get_local_mouse_position();
433-
const bool movement_threshold_passed = original_mouse_pos.distance_to(mouse_pos) > 4 * EDSCALE;
433+
const bool movement_threshold_passed = original_mouse_pos.distance_to(mouse_pos) > 4.0f * EDSCALE;
434434
if (orbiting_index == p_index && gizmo_activated && movement_threshold_passed) {
435435
if (Input::get_singleton()->get_mouse_mode() == Input::MOUSE_MODE_VISIBLE) {
436436
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
@@ -2220,7 +2220,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
22202220
if (change_nav_from_shortcut != NAVIGATION_NONE) {
22212221
nav_mode = change_nav_from_shortcut;
22222222
} else {
2223-
const bool movement_threshold_passed = _edit.original_mouse_pos.distance_to(_edit.mouse_pos) > 8 * EDSCALE;
2223+
const bool movement_threshold_passed = _edit.original_mouse_pos.distance_to(_edit.mouse_pos) > 8.0f * EDSCALE;
22242224

22252225
if ((selection_in_progress || clicked_wants_append) && movement_threshold_passed && clicked.is_valid()) {
22262226
cursor.region_select = true;

editor/scene/3d/path_3d_editor_plugin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ EditorPlugin::AfterGUIInput Path3DEditorPlugin::forward_3d_gui_input(Camera3D *p
619619
real_t cdist = from.distance_to(to);
620620
from = gt.xform(from);
621621
to = gt.xform(to);
622-
if (cdist > 0) {
622+
if (cdist > 0.0f) {
623623
const Vector2 segment_a = viewport->point_to_screen(from);
624624
const Vector2 segment_b = viewport->point_to_screen(to);
625625
Vector2 inters = Geometry2D::get_closest_point_to_segment(mbpos, segment_a, segment_b);
@@ -1090,8 +1090,8 @@ int Path3DGizmoPlugin::subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo,
10901090

10911091
if (Path3DEditorPlugin::singleton->curve_edit->is_pressed()) {
10921092
for (int idx = 0; idx < curve->get_point_count(); ++idx) {
1093-
Vector3 pos = path->get_global_transform().xform(curve->get_point_position(idx));
1094-
if (p_camera->unproject_position(pos).distance_to(p_point) < 20) {
1093+
const Vector3 pos = path->get_global_transform().xform(curve->get_point_position(idx));
1094+
if (p_camera->unproject_position(pos).distance_to(p_point) < 20.0f) {
10951095
return idx;
10961096
}
10971097
}

editor/scene/3d/polygon_3d_editor_plugin.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ EditorPlugin::AfterGUIInput Polygon3DEditor::forward_3d_gui_input(Camera3D *p_ca
145145
PackedVector2Array poly = _get_polygon();
146146

147147
//first check if a point is to be added (segment split)
148-
real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
148+
const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius");
149149

150150
switch (mode) {
151151
case MODE_CREATE: {
@@ -196,9 +196,9 @@ EditorPlugin::AfterGUIInput Polygon3DEditor::forward_3d_gui_input(Camera3D *p_ca
196196
}
197197

198198
//search edges
199-
int closest_idx = -1;
200199
Vector2 closest_pos;
201200
real_t closest_dist = 1e10;
201+
int closest_idx = -1;
202202
for (int i = 0; i < poly.size(); i++) {
203203
const Vector2 segment_a = p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth)));
204204
const Vector2 segment_b = p_camera->unproject_position(gt.xform(Vector3(poly[(i + 1) % poly.size()].x, poly[(i + 1) % poly.size()].y, depth)));
@@ -208,9 +208,9 @@ EditorPlugin::AfterGUIInput Polygon3DEditor::forward_3d_gui_input(Camera3D *p_ca
208208
continue; //not valid to reuse point
209209
}
210210

211-
real_t d = cp.distance_to(gpoint);
212-
if (d < closest_dist && d < grab_threshold) {
213-
closest_dist = d;
211+
const real_t dist = cp.distance_to(gpoint);
212+
if (dist < closest_dist && dist < grab_threshold) {
213+
closest_dist = dist;
214214
closest_pos = cp;
215215
closest_idx = i;
216216
}
@@ -230,15 +230,15 @@ EditorPlugin::AfterGUIInput Polygon3DEditor::forward_3d_gui_input(Camera3D *p_ca
230230
} else {
231231
//look for points to move
232232

233-
int closest_idx = -1;
234233
Vector2 closest_pos;
235234
real_t closest_dist = 1e10;
235+
int closest_idx = -1;
236236
for (int i = 0; i < poly.size(); i++) {
237237
Vector2 cp = p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth)));
238238

239-
real_t d = cp.distance_to(gpoint);
240-
if (d < closest_dist && d < grab_threshold) {
241-
closest_dist = d;
239+
const real_t dist = cp.distance_to(gpoint);
240+
if (dist < closest_dist && dist < grab_threshold) {
241+
closest_dist = dist;
242242
closest_pos = cp;
243243
closest_idx = i;
244244
}
@@ -275,15 +275,15 @@ EditorPlugin::AfterGUIInput Polygon3DEditor::forward_3d_gui_input(Camera3D *p_ca
275275
}
276276
}
277277
if (mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed() && edited_point == -1) {
278-
int closest_idx = -1;
279278
Vector2 closest_pos;
280279
real_t closest_dist = 1e10;
280+
int closest_idx = -1;
281281
for (int i = 0; i < poly.size(); i++) {
282282
Vector2 cp = p_camera->unproject_position(gt.xform(Vector3(poly[i].x, poly[i].y, depth)));
283283

284-
real_t d = cp.distance_to(gpoint);
285-
if (d < closest_dist && d < grab_threshold) {
286-
closest_dist = d;
284+
const real_t dist = cp.distance_to(gpoint);
285+
if (dist < closest_dist && dist < grab_threshold) {
286+
closest_dist = dist;
287287
closest_pos = cp;
288288
closest_idx = i;
289289
}

editor/scene/3d/skeleton_3d_editor_plugin.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,17 +1517,17 @@ int Skeleton3DGizmoPlugin::subgizmos_intersect_ray(const EditorNode3DGizmo *p_gi
15171517
}
15181518

15191519
// Select bone.
1520-
real_t grab_threshold = 4 * EDSCALE;
1521-
Vector3 ray_from = p_camera->get_global_transform().origin;
1522-
Transform3D gt = skeleton->get_global_transform();
1523-
int closest_idx = -1;
1520+
const Transform3D gt = skeleton->get_global_transform();
1521+
const Vector3 ray_from = p_camera->get_global_transform().origin;
1522+
const real_t grab_threshold = 4.0f * EDSCALE;
15241523
real_t closest_dist = 1e10;
1524+
int closest_idx = -1;
15251525
const int bone_count = skeleton->get_bone_count();
15261526
for (int i = 0; i < bone_count; i++) {
1527-
Vector3 joint_pos_3d = gt.xform(skeleton->get_bone_global_pose(i).origin);
1528-
Vector2 joint_pos_2d = p_camera->unproject_position(joint_pos_3d);
1529-
real_t dist_3d = ray_from.distance_to(joint_pos_3d);
1530-
real_t dist_2d = p_point.distance_to(joint_pos_2d);
1527+
const Vector3 joint_pos_3d = gt.xform(skeleton->get_bone_global_pose(i).origin);
1528+
const Vector2 joint_pos_2d = p_camera->unproject_position(joint_pos_3d);
1529+
const real_t dist_3d = ray_from.distance_to(joint_pos_3d);
1530+
const real_t dist_2d = p_point.distance_to(joint_pos_2d);
15311531
if (dist_2d < grab_threshold && dist_3d < closest_dist) {
15321532
closest_dist = dist_3d;
15331533
closest_idx = 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;

0 commit comments

Comments
 (0)