From 3fa775b844a9505dc891a64356d22d7aa3809c40 Mon Sep 17 00:00:00 2001 From: arkology <43543909+arkology@users.noreply.github.com> Date: Fri, 3 Jan 2025 20:32:08 +0300 Subject: [PATCH] Speed up `Line2D._edit_get_rect()` --- scene/2d/line_2d.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index 734db2ea2b3c..d165d477f84b 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -41,13 +41,13 @@ Rect2 Line2D::_edit_get_rect() const { if (_points.size() == 0) { return Rect2(0, 0, 0, 0); } - Vector2 d = Vector2(_width, _width); - Rect2 bounding_rect = Rect2(_points[0] - d, 2 * d); + Vector2 min = _points[0]; + Vector2 max = min; for (int i = 1; i < _points.size(); i++) { - bounding_rect.expand_to(_points[i] - d); - bounding_rect.expand_to(_points[i] + d); + min = min.min(_points[i]); + max = max.max(_points[i]); } - return bounding_rect; + return Rect2(min, max - min).grow(_width); } bool Line2D::_edit_use_rect() const {