Skip to content

Drop triangles with coincident vertices from Shape.tessellate - #2122

Open
LiShuochen wants to merge 1 commit into
CadQuery:masterfrom
LiShuochen:fix-tessellate-degenerate-triangles
Open

LiShuochen wants to merge 1 commit into
CadQuery:masterfrom
LiShuochen:fix-tessellate-degenerate-triangles

Conversation

@LiShuochen

Copy link
Copy Markdown

Where a surface collapses to a point (sphere poles, a cone apex, a revolved profile ending on its axis, the center of a horn torus, the corner patches of a filleted box), BRepMesh creates several nodes with identical coordinates. The triangles spanning two of them have zero area and no normal, and tessellate passed them on to the AMF, 3MF and TJS exports.

import cadquery as cq

verts, tris = cq.Workplane().sphere(10).val().tessellate(1e-2)
print(sum((verts[b] - verts[a]).cross(verts[c] - verts[a]).Length == 0 for a, b, c in tris))
# 2 on master, 0 with this change

tessellate now skips these triangles; the vertex list is unchanged, so vertex indices stay the same. STL export does not go through tessellate and still contains them. Only exact coincidence is checked, so triangles with distinct but collinear or nearly coincident vertices, such as a few next to the straight edges of a half cone or at the center of a horn torus, are left as they are.

Reading nodes with Coord() and triangles with Get() offsets the cost of the check, so tessellate is about as fast as before.

Where a surface collapses to a point (sphere poles, a cone apex, a revolved
profile ending on its axis, the center of a horn torus, the corner patches of
a filleted box), BRepMesh creates several nodes with identical coordinates.
The triangles between them have zero area and were passed on to the AMF, 3MF
and TJS exports. Skip them; the vertex list is unchanged.
@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.82%. Comparing base (8178185) to head (afb398d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2122      +/-   ##
==========================================
+ Coverage   95.81%   95.82%   +0.01%     
==========================================
  Files          30       30              
  Lines        9605     9606       +1     
  Branches     1443     1443              
==========================================
+ Hits         9203     9205       +2     
+ Misses        247      246       -1     
  Partials      155      155              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants