forked from 1b-agent/opencadstudio-upstream
PolyfaceMesh and SubD Mesh faces were fan-triangulated from vertex 0, which is only valid for convex faces. A concave face (e.g. an L-shaped / notched n-gon) fanned into triangles that spill outside the outline — spurious "triangles that shouldn't be there" that covered neighbouring geometry and its edges. Replace the fan with an ear-clipping triangulator that projects the planar face to 2D, respects its winding, and clips only real ears, so concave faces triangulate to exactly their own area. Convex faces (and the cylinder-cap n-gons) are unchanged in result. Falls back to a fan for a degenerate / self-intersecting polygon. Verified on Annotation-2D-Mesh-Solid-BIM.dwg (concave 5-/6-gon mesh faces) and by a unit test: a concave L-hexagon triangulates to n-2 triangles whose total area equals the polygon's, with no overshoot. Co-Authored-By: Claude Opus 4.8 <[email protected]>