File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -1171,20 +1171,34 @@ static bool exportGroupsToShape(shape_t *shape,
1171
1171
area += (v0x * v1y - v0y * v1x) * static_cast <real_t >(0.5 );
1172
1172
}
1173
1173
1174
- int maxRounds = 10 ; // arbitrary max loop count to protect against
1175
- // unexpected errors
1176
1174
1177
1175
face_t remainingFace = face; // copy
1178
1176
size_t guess_vert = 0 ;
1179
1177
vertex_index_t ind[3 ];
1180
1178
real_t vx[3 ];
1181
1179
real_t vy[3 ];
1182
- while (remainingFace.vertex_indices .size () > 3 && maxRounds > 0 ) {
1180
+
1181
+ // How many iterations can we do without decreasing the remaining
1182
+ // vertices.
1183
+ size_t remainingIterations = face.vertex_indices .size ();
1184
+ size_t previousRemainingVertices = remainingFace.vertex_indices .size ();
1185
+
1186
+ while (remainingFace.vertex_indices .size () > 3 && remainingIterations > 0 ){
1183
1187
npolys = remainingFace.vertex_indices .size ();
1184
1188
if (guess_vert >= npolys) {
1185
- maxRounds -= 1 ;
1186
1189
guess_vert -= npolys;
1187
1190
}
1191
+
1192
+ if (previousRemainingVertices != npolys) {
1193
+ // The number of remaining vertices decreased. Reset counters.
1194
+ previousRemainingVertices = npolys;
1195
+ remainingIterations = npolys;
1196
+ } else {
1197
+ // We didn't consume a vertex on previous iteration, reduce the
1198
+ // available iterations.
1199
+ remainingIterations--;
1200
+ }
1201
+
1188
1202
for (size_t k = 0 ; k < 3 ; k++) {
1189
1203
ind[k] = remainingFace.vertex_indices [(guess_vert + k) % npolys];
1190
1204
size_t vi = size_t (ind[k].v_idx );
You can’t perform that action at this time.
0 commit comments