test(cpp): follow the clean-up in the goldens, guard the diagnosis builders, format (CI of #88)

DECISION: the roller-chain sprocket goldens and the C++ expectation move to the cleaned topology; they are not held at the
old counts. The port is now deliberately different from the 2.2.6 reference on this point.

WHAT CI SAID, AND WHY EACH ITEM IS RIGHT TO CHANGE
- C++ doctest `std` (test_chain_bearing.cpp): the 12B sprocket has 39 faces, not 54. The sprocket is a body cut by tooth
  and roller profiles; cut now unifies the faces a cylinder seam had split. Volume, area, bounding box, tags are equal to
  the golden to 1e-6, so the geometry is the same and only the split faces are gone.
- src/cpp/tests/golden/std_sprocket.json (faces 54 -> 39, edges 156 -> 111) and std_sprocket_unbored.json (35 -> 26 faces,
  99 -> 72 edges): these files are recorded from the 2.2.6 Python reference SDK, which does not clean after a cut, and the
  suite refuses SCAD_REGOLDEN in CI, so they cannot be re-recorded there. I edited the four numbers by hand after
  comparing the port's whole output with the golden field by field: nothing else differs. Anyone who re-records from a
  reference that cleans will get the same numbers.
- test_signatures_match_python: cut_rsolid has the keyword `clean` now.
- OCCT guard audit: the trial blend of the new split-faces probe built BRepFilletAPI_Make* outside occt_guard. It runs
  under occt_guard now (a crash inside is a KernelError, which the diagnosis already swallows).
- clang-format 18.1.8 (installed from pip into a scratch venv): blends.cpp and blend_diagnosis.cpp.

CHECKED HERE: src/cpp/tests/python 556 passed (2 failures, test_locator_checks and test_failures, are Windows-only and
did not fail in CI), check_occt_guard --strict 0, check_format.sh clean. The doctest executables were not built here;
the CI run of this commit is the check for them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Ni Jingzhe
2026-11-12 04:06:38 +08:00
parent 35a4e5efa9
commit ee5668c31a
6 changed files with 33 additions and 30 deletions
+22 -19
View File
@@ -162,9 +162,9 @@ std::optional<BlendDiagnosis> classify_tangent_adjacency(const Case& c) {
}
// A boolean that was not cleaned leaves faces that lie on one surface split (a cylinder wall cut along its seam is two
// faces). The blend of an edge along such a face fails, or goes wrong, and the room probe below then blames the radius:
// the "face room" it measures is only the half the seam cut off. Unify the same-domain faces, carry the selected edges
// over with the history, and blend again: when that works, the split faces are the cause (issue #88).
// faces). The blend of an edge along such a face fails, or goes wrong, and the room probe below then blames the
// radius: the "face room" it measures is only the half the seam cut off. Unify the same-domain faces, carry the
// selected edges over with the history, and blend again: when that works, the split faces are the cause (issue #88).
std::optional<BlendDiagnosis> classify_split_faces(const Case& c) {
ShapeUpgrade_UnifySameDomain unifier(c.solid.wrapped(), /*UnifyEdges=*/true, /*UnifyFaces=*/true,
/*ConcatBSplines=*/true);
@@ -200,35 +200,38 @@ std::optional<BlendDiagnosis> classify_split_faces(const Case& c) {
const bool chamfer = c.words.size == "distance";
const char* kind = chamfer ? "chamfer" : "fillet";
bool works = false;
if (chamfer) {
BRepFilletAPI_MakeChamfer blend(unified);
for (const TopoDS_Edge& edge : edges)
blend.Add(c.size_value, edge);
blend.Build();
works = blend.IsDone() && BRepCheck_Analyzer(blend.Shape()).IsValid() == Standard_True;
} else {
const bool works = occt_guard([&] {
if (chamfer) {
BRepFilletAPI_MakeChamfer blend(unified);
for (const TopoDS_Edge& edge : edges)
blend.Add(c.size_value, edge);
blend.Build();
return blend.IsDone() && BRepCheck_Analyzer(blend.Shape()).IsValid() == Standard_True;
}
BRepFilletAPI_MakeFillet blend(unified);
for (const TopoDS_Edge& edge : edges)
blend.Add(c.size_value, edge);
blend.Build();
works = blend.IsDone() && BRepCheck_Analyzer(blend.Shape()).IsValid() == Standard_True;
}
return blend.IsDone() && BRepCheck_Analyzer(blend.Shape()).IsValid() == Standard_True;
});
if (!works)
return std::nullopt;
BlendDiagnosis out;
out.failure_kind = "faces_split_on_one_surface";
out.what_happened = std::to_string(split) + " face(s) of the solid are split on a surface they share with a neighbour " +
"(typically a boolean made without clean, or a cylinder wall cut along its seam); the same " + kind +
" " + c.words.size + " " + g4(c.size_value) +
out.what_happened = std::to_string(split) +
" face(s) of the solid are split on a surface they share with a neighbour " +
"(typically a boolean made without clean, or a cylinder wall cut along its seam); the same " +
kind + " " + c.words.size + " " + g4(c.size_value) +
" mm succeeds once those faces are unified, so the " + c.words.size + " is not the limit";
out.possible_causes = {"A cut or intersection ran with clean=False and left a face split along its seam.",
"The solid came from a source that does not unify faces (an imported or hand-built shape)."};
out.measurements = {{"split_faces", static_cast<double>(split), "faces"}, {c.words.size, c.size_value, "mm"}};
out.repair = {"Make the cut / intersect with clean=True (the default), or pass the solid through union_rsolid(solid, "
"clean=True) before the " + std::string(kind) + ".",
std::string("Keep the ") + c.words.size + " as it is: it is not too large."};
out.repair = {
"Make the cut / intersect with clean=True (the default), or pass the solid through union_rsolid(solid, "
"clean=True) before the " +
std::string(kind) + ".",
std::string("Keep the ") + c.words.size + " as it is: it is not too large."};
return out;
}
+5 -5
View File
@@ -52,11 +52,11 @@ struct BlendAttempt {
spec.possible_causes = diagnosis->possible_causes;
const std::string details =
violation != nullptr ? std::string(dynamic_cast<const BlendValidityViolation*>(&error) != nullptr
? "BlendValidityViolation: "
: "BlendVolumeViolation: ") +
violation->what()
: technical_details_of(error);
violation != nullptr
? std::string(dynamic_cast<const BlendValidityViolation*>(&error) != nullptr ? "BlendValidityViolation: "
: "BlendVolumeViolation: ") +
violation->what()
: technical_details_of(error);
std::vector<ErrorEvidence> evidence;
if (diagnosis && !diagnosis->evidence_edges.empty()) {
// The solid with the implicated edges in orange; the same failure at the same size is drawn once per process
+1 -1
View File
@@ -11,7 +11,7 @@ using doctest::Approx;
TEST_CASE("sprocket: ISO 606 12B candidate") {
const Solid sprocket = make_roller_chain_sprocket_rsolid(18, 19.05, 12.07, 11.1, 10.2);
CHECK(sprocket.volume() == Approx(98201.67369173263).epsilon(1e-6));
CHECK(sprocket.faces().size() == 54);
CHECK(sprocket.faces().size() == 39); // 54 before cut unified the faces a cylinder seam split (issue #88)
const Value meta = sprocket.get_metadata("std.chain.roller_sprocket");
CHECK(meta.find("n_teeth")->as_int() == 18);
CHECK(number(meta, "pitch_radius") == Approx(19.05 / (2.0 * std::sin(kPi / 18))));
+2 -2
View File
@@ -20,8 +20,8 @@
59.38481593313661,
11.1
],
"edges": 156,
"faces": 54,
"edges": 111,
"faces": 39,
"tags": [
"solid.boolean.cut"
],
@@ -20,8 +20,8 @@
27.35284634516466,
5.0
],
"edges": 99,
"faces": 35,
"edges": 72,
"faces": 26,
"tags": [
"solid.boolean.cut"
],
@@ -119,5 +119,5 @@ def test_2d_booleans():
def test_signatures_match_python():
assert parameter_names(scad.union_rsolid) == ["solids", "clean", "glue", "tol", "tracking_policy"] # *solids
# on_split: a cut that splits the body returns its pieces by default (notebook values; a Part holds one solid), "error" refuses
assert parameter_names(scad.cut_rsolid) == ["solids", "skip_non_intersecting", "tracking_policy", "on_split"]
assert parameter_names(scad.cut_rsolid) == ["solids", "skip_non_intersecting", "tracking_policy", "on_split", "clean"]
assert parameter_names(scad.boolean_rsolidlist) == ["left", "right", "operation"]