Update `triangulate_delaunay()` to avoid needless reallocations

This commit is contained in:
Jakub Marcowski 2023-10-16 12:26:59 +02:00
parent 5fb9ff9986
commit c33e291474
1 changed files with 5 additions and 3 deletions

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;
}