1
0
Fork 0

Merge pull request #101082 from arkology/line_2d_edit_get_rect

Speed up `Line2D._edit_get_rect()`
This commit is contained in:
Rémi Verschelde 2025-01-06 22:48:35 +01:00
commit 08c605fe2d
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 5 additions and 5 deletions

View File

@ -41,13 +41,13 @@ Rect2 Line2D::_edit_get_rect() const {
if (_points.size() == 0) { if (_points.size() == 0) {
return Rect2(0, 0, 0, 0); return Rect2(0, 0, 0, 0);
} }
Vector2 d = Vector2(_width, _width); Vector2 min = _points[0];
Rect2 bounding_rect = Rect2(_points[0] - d, 2 * d); Vector2 max = min;
for (int i = 1; i < _points.size(); i++) { for (int i = 1; i < _points.size(); i++) {
bounding_rect.expand_to(_points[i] - d); min = min.min(_points[i]);
bounding_rect.expand_to(_points[i] + d); max = max.max(_points[i]);
} }
return bounding_rect; return Rect2(min, max - min).grow(_width);
} }
bool Line2D::_edit_use_rect() const { bool Line2D::_edit_use_rect() const {