Repository navigation
CAD surface export: bisect self-intersecting UV trim chords at tangent cusps - #376
Merged
Merged
Conversation
…t cusps (stevecad#360) When OpenCascade's BRepMesh fails trim matching (such as a zero-angle tangent cusp where independent edge chords cross in UV regardless of deflection), inspect each face's UV trim polygon with exact 2D predicates (IEEE-754 filter with exact Fraction fallback), bisect offending curved chords at their mid parameter on the real CAD edge across every incident face in IMeshData_Model, and let BRepMesh triangulate with those shared nodes. Refuses cleanly with a message naming the tangent cusp if the per-face bisection cap is hit, if straight edges self-intersect, or if bisection reaches parameter resolution. Adds regression tests in python/tests/test_cad_cusps.py with independent watertight, trim-to-mesh, facet-to-CAD, cap-refusal, and native verifier checks, and updates ARCHITECTURE.md and library-capabilities.md. Closes stevecad#360
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #360
Root cause
OpenCascade discretises adjacent curved edges independently. At a tangent cusp the arc-side node falls below the spline chord, so the arc chord crosses the spline chord in UV. BRepMesh_ModelHealer leaves the wire alone, and FaceDiscret builds only 2 triangles, which omit the cusp tip.
_face_datacorrectly refuses the trim/boundary mismatch ("CAD trim chains do not cover mesh boundary exactly once"). The crossing condition is scale independent, so finer deflection and tighter tolerances hit it again on every retry.What changed
python/camlib/_cad_surface.py: 354 changed lines against upstream/main b636cc4, and no Rust changes._find_uv_trim_conflictfinds crossing chords, endpoint touches, 180-degree foldbacks, zero-length chords and inverted wires._bisect_model_edgeevaluates the real CAD edge, and the 2D pcurve in every face of that edge, at the exact mid parameter. It inserts that shared node into all of them, so shared edges stay welded._mesh_solid_with_cusp_repairruns only after the normal mesher hits a mismatch, so solids that already mesh are untouched. It runs BRepMesh withInParallel = Falseso the repair path is deterministic; the normal upstream meshing path is unchanged. The count is reported ascusp_trim_bisectionsinSurfaceMesh.source.IMeshData_Failureon the face andIMeshData_SelfIntersectingWireon its wires. A probe showed these are the only two that block FaceDiscret.docs/ARCHITECTURE.mdanddocs/library-capabilities.mdare updated.Error accounting (refuse rather than approximate)
_MAX_CUSP_BISECTIONS_PER_FACE).Tests added
python/tests/test_cad_cusps.pyis new: 477 lines, 12 test methods._bisect_model_edgefailure reasons checked with a fake edge.Verification (rebased onto upstream/main b636cc4, HEAD e640311, local run 2026-11-21, log D:\camlib-swarm\final-360c.log)
cargo build --release --workspace --all-features: exit 0.ruff check python: All checks passed.ruff format --check python: 230 files already formatted.python -m unittest discover -s python/tests: Ran 1098 tests in 930.279s, OK (skipped=21), with 0 failures and 0 errors.InParallel = FalsevsTrue: the warm repro median was 0.0245 s vs 0.0258 s, and test_cad_cusps was unchanged within noise.Platforms run: Windows 11 x64, Python 3.12.14, CadQuery 2.8.0, OCP 7.9.3.1. Linux and macOS were not run. Rust checks (cargo test/clippy/fmt) were not run because no Rust files changed.
Left alone
While sweeping 250 random cusp prisms I found a separate refusal in the spline-spline sliver weld check. Six spline_spline cases that mesh without cusp repair were later refused by the conforming refinement weld check. It is pre-existing and independent of #360, and I did not weaken check_weld. It should get its own issue.
Merge note: this PR and #361 both touch the same trim check in
export_curved_solid, so whichever merges second needs a small rebase.Review notes
(ImportError, AttributeError)guard wraps the whole repair, so an AttributeError from a bug in the repair code itself would also be reported as "unavailable on this OCP version". It is still a refusal, never an approximation.