simplifyRing function
Removes exact consecutive duplicates and zero-width spikes a, b, a
(spec 07 D6). Stored-value comparisons, so exact; zero area, so the tiling
is unchanged. Without it the triangulator refuses a pinched outline.
Implementation
List<Vector2> simplifyRing(List<Vector2> ring) {
final r = [...ring];
var changed = true;
while (changed && r.length > 3) {
changed = false;
for (var i = 0; i < r.length && r.length > 3; i++) {
final prev = r[(i - 1 + r.length) % r.length];
final next = r[(i + 1) % r.length];
if (_same(r[i], next)) {
r.removeAt(i);
changed = true;
break;
}
if (_same(prev, next)) {
// a, b, a -> a: drop b and the repeated a.
final j = (i + 1) % r.length;
if (j > i) {
r.removeAt(j);
r.removeAt(i);
} else {
r.removeAt(i);
r.removeAt(j);
}
changed = true;
break;
}
}
}
return r;
}