Merge pull request #83434 from Chubercik/optimize_triangulate_delaunay

Update `triangulate_delaunay()` to avoid needless reallocations
This commit is contained in:
Rémi Verschelde 2023-10-22 12:11:53 +02:00
commit 14913f178b
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -306,10 +306,12 @@ public:
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;
}