From bb5d130509156e48bdd22d68c780bfa69b28a270 Mon Sep 17 00:00:00 2001 From: Anilforextra Date: Thu, 10 Feb 2022 15:21:17 +0545 Subject: [PATCH] Code quality cleanup for some variable scopes. --- editor/plugins/abstract_polygon_2d_editor.cpp | 7 +++---- scene/2d/line_2d.cpp | 6 +++--- scene/2d/node_2d.cpp | 3 +-- scene/2d/polygon_2d.cpp | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index c6bde4c98a21..bad78c0dfbe6 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -286,15 +286,14 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref &p_event) _commit_action(); return true; } else { - Vector vertices2 = _get_polygon(insert.polygon); - pre_move_edit = vertices2; + pre_move_edit = vertices; edited_point = PosVertex(insert.polygon, insert.vertex + 1, xform.affine_inverse().xform(insert.pos)); - vertices2.insert(edited_point.vertex, edited_point.pos); + vertices.insert(edited_point.vertex, edited_point.pos); selected_point = Vertex(edited_point.polygon, edited_point.vertex); edge_point = PosVertex(); undo_redo->create_action(TTR("Insert Point")); - _action_set_polygon(insert.polygon, vertices2); + _action_set_polygon(insert.polygon, vertices); _commit_action(); return true; } diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index 7f2290bdc731..c19a58228603 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -268,15 +268,15 @@ bool Line2D::get_antialiased() const { } void Line2D::_draw() { - if (_points.size() <= 1 || _width == 0.f) { + int len = _points.size(); + if (len <= 1 || _width == 0.f) { return; } // TODO Is this really needed? // Copy points for faster access Vector points; - points.resize(_points.size()); - int len = points.size(); + points.resize(len); { const Vector2 *points_read = _points.ptr(); for (int i = 0; i < len; ++i) { diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 9d2654324390..dd88bda30424 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -244,10 +244,9 @@ Point2 Node2D::get_global_position() const { } void Node2D::set_global_position(const Point2 &p_pos) { - Transform2D inv; CanvasItem *pi = get_parent_item(); if (pi) { - inv = pi->get_global_transform().affine_inverse(); + Transform2D inv = pi->get_global_transform().affine_inverse(); set_position(inv.xform(p_pos)); } else { set_position(p_pos); diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp index 1f4dec686499..5f92e68e6945 100644 --- a/scene/2d/polygon_2d.cpp +++ b/scene/2d/polygon_2d.cpp @@ -295,14 +295,14 @@ void Polygon2D::_notification(int p_what) { } Vector colors; + colors.resize(len); + if (vertex_colors.size() == points.size()) { - colors.resize(len); const Color *color_r = vertex_colors.ptr(); for (int i = 0; i < len; i++) { colors.write[i] = color_r[i]; } } else { - colors.resize(len); for (int i = 0; i < len; i++) { colors.write[i] = color; }