The issue appears to be fairly simple (incorrect linked list pointers due to out of order items removal), but I'm not familiar with the code, so it might be something more serious. Patched version seem to produce correct-looking output, at least.
Diff (a PR seems rather excessive): diff.txt
And, one of the offending polygons: polygon.txt