Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions editor/scene/2d/abstract_polygon_2d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ Vector2 AbstractPolygon2DEditor::_get_geometric_center() const {
int n_subs = 0;
for (int i = 0; i < n_polygons; i++) {
const Vector<Vector2> &vertices = _get_polygon(i);
// Don't try to decompose a polygon if it's not yet a polygon :)
if (vertices.size() < 3) {
continue;
}
Vector<Vector<Point2>> decomp = ::Geometry2D::decompose_polygon_in_convex(vertices);
if (decomp.is_empty()) {
continue;
Expand All @@ -167,6 +171,11 @@ Vector2 AbstractPolygon2DEditor::_get_geometric_center() const {
}
n_subs += decomp.size();
}

if (n_subs == 0) {
return Vector2();
}

cx /= n_subs;
cy /= n_subs;

Expand Down
Loading