Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add polygon test showing bad tessellation result + fix #824

Merged
merged 2 commits into from
May 28, 2024

Conversation

kintel
Copy link
Contributor

@kintel kintel commented May 26, 2024

I believe this shows that a relatively complex "branchy" polygon with a single triangular hole causes Triangulate() to emit some pretty funky triangles.

This polygons is a very slimmed down version of the polygon emitted by https://github.com/openscad/openscad/blob/master/examples/Advanced/module_recursion.scad

The polygon itself is a result or a union of a large number of 2D rectangles using Clipper V1.
It's very possible that there is some precision-related issue causing this, but I believe that a robust triangulator should be able to handle this kind of abuse.

PS! validated by emitting the triangles as an OBJ file and rendering that externally:

std::cout << "# polygon-test.cc\n";
  for (auto poly : polys) {
    for (auto v : poly) {
      std::cout << "v " << v[0] << " " << v[1] << " 0\n";
    }
  }
  for (auto tri : triangles) {
    std::cout << "f " << tri[0] + 1 << " " << tri[1] + 1 << " " << tri[2] + 1
              << "\n";
  }

@kintel kintel mentioned this pull request May 26, 2024
10 tasks
@elalish
Copy link
Owner

elalish commented May 28, 2024

Indeed, this is a valid polygon and a good test case. Turns out a couple of valid ears were being rejected (positive cost) due to verts near their tip. I've improved their neighbor checking to get correct costs, so now everything proceeds properly.

@elalish elalish changed the title Add polygon test showing bad tessellation result Add polygon test showing bad tessellation result + fix May 28, 2024
Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.23%. Comparing base (d437097) to head (0e6d0db).
Report is 32 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #824      +/-   ##
==========================================
- Coverage   91.84%   89.23%   -2.61%     
==========================================
  Files          37       61      +24     
  Lines        4976     8482    +3506     
  Branches        0      932     +932     
==========================================
+ Hits         4570     7569    +2999     
- Misses        406      913     +507     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@elalish elalish merged commit 376d317 into elalish:master May 28, 2024
20 checks passed
@kintel kintel deleted the kintel-polygon-test branch May 28, 2024 19:45
@kintel
Copy link
Contributor Author

kintel commented May 29, 2024

Awesome - tested and works perfectly also with extra torture:

out

@kintel
Copy link
Contributor Author

kintel commented Jun 4, 2024

@elalish I've got another one. It's a bit time consuming to manually trim polygons to minimal examples. Do you have a good/preferred way of providing data-driven polygon tests?

@elalish
Copy link
Owner

elalish commented Jun 4, 2024

If you compile with MANIFOLD_DEBUG and set ManifoldParams().processOverlaps = false, then it will error out when a bad triangulation is found and print out a test case to the command line that you can copy directly into our tests, like this.

@kintel
Copy link
Contributor Author

kintel commented Jun 5, 2024

After a while I figured out it's PolygonParams(), not ManifoldParams(). Will open a new ticket.

@elalish
Copy link
Owner

elalish commented Jun 5, 2024

Oh, oops - you're right.

@elalish elalish mentioned this pull request Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants