Skip to content

Commit

Permalink
Merge pull request #83434 from Chubercik/optimize_triangulate_delaunay
Browse files Browse the repository at this point in the history
Update `triangulate_delaunay()` to avoid needless reallocations
  • Loading branch information
akien-mga committed Oct 22, 2023
2 parents 6bf936c + c33e291 commit 14913f1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/math/geometry_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,12 @@ class Geometry2D {
Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(p_points);
Vector<int> triangles;

triangles.resize(3 * tr.size());
int *ptr = triangles.ptrw();
for (int i = 0; i < tr.size(); i++) {
triangles.push_back(tr[i].points[0]);
triangles.push_back(tr[i].points[1]);
triangles.push_back(tr[i].points[2]);
*ptr++ = tr[i].points[0];
*ptr++ = tr[i].points[1];
*ptr++ = tr[i].points[2];
}
return triangles;
}
Expand Down

0 comments on commit 14913f1

Please sign in to comment.