[WIP] Ignore all flat triangles in triangulation #2248
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This partially fixes #2247. By ignoring flat/zero-area triangles (i.e. where all three points are collinear), we avoid the assertion failure associated with overwriting the entry in
_edges_lookup
. But there is still an unexpected triangle and vertex in the output.I added a few simple and similar tests to capture what I expect from the output, and where the behavior breaks down. Before the change both
test_triangulate_collinear_path
andtest_triangulate_collinear_path_with_repeat
fail with the assertion failure. After the change, onlytest_triangulate_collinear_path_with_repeat
fails, not due to the assertion, but because a triangle is found, which also contains a vertex that is not in the input - instead I would expect no triangles to be returned.I think this PR represents a small improvement from
main
for two reasons.# ignore flat tris
, which suggested that the_add_tri
was trying to skip zero-area triangles. But the implementation only ignored triangles with at least 2 points that have duplicate coordinates. This PR adds a proper check for that condition.However, I have some reservations about this PR in its current state.
Note that some of the test cases represent degenerate cases, so I think an alternative fix here is to raise an exception with a suitable message and document that behavior. Personally, I would expect a triangulation algorithm to expect some degenerate cases and handle them fairly gracefully (perhaps with a warning), but this is my first time thinking about triangulation, so I'm very much a beginner here.
Any thoughts/comments/ideas welcome!