A stray click must not break a model that looks perfect on screen

Revolve failed on a sketch whose profile was closed. Decoding the reported 3mf: four
entities forming a proper closed loop (joints open by 4.44e-06 mm, well inside
tolerance) plus one stray 1.82 mm Line at (-24.2, 80.3), inside the shaded region,
touching nothing.

The viewport's region_loops discards open chains ON PURPOSE — it exists to find
EXTRUDABLE regions — so the user saw one clean closed region. entities_to_wires kept
the stray as its own one-edge loop, so it returned two wires, and Revolve goes through
entities_to_wire which demands exactly one. Extrude would have failed one step later in
wires_to_face, because a one-edge open wire bounds no face. Same class as the tolerance
split fixed in 8b568b7b: the viewport and the kernel disagreeing about the sketch — this
time about what BELONGS to the profile.

entities_to_wires/entities_to_wire/build_sketch_wire take closed_only. It is not a
blanket rule: a SurfaceExtrude builds a sheet FROM an open profile and a Sweep PATH is
normally open, so all ten call sites are classified individually — true for the face
fallback, Extrude-taper, Revolve, the Sweep PROFILE and Loft profiles; false for
SurfaceExtrude/Revolve/Loft/Fill and the Sweep path.

A component counts as open when some welded node has DEGREE 1. The first attempt used
"the traversal did not return to its starting node", which regressed the bridged C
profile: a closed loop that also carries a second edge across the same two nodes has no
free endpoint, but its Eulerian walk ends elsewhere. Degree-1 is the property that
actually distinguishes a stray segment from a closed profile; the suite caught the
difference.

Behaviour change decided by Tommaso: a stray is IGNORED, not refused. The test that
required refusal dates from when ignoring meant falling through to a default rectangle —
geometry nobody drew. That fallback is gone, so ignoring now builds the circle the user
actually drew. Its assertion is updated with the reason.

The bridge round-trip test extruded an ENTIRELY open chain and "worked" only because
OCCT will make a face from an open wire. It gets a genuinely closed profile: the test is
about serialization, and deserialize_recipe recomputes, so the document has to be one
that legitimately builds.

Failures now say WHERE. sketch_open_ends reports free endpoints under the same weld
tolerance the wire build uses, and open_loop_message is shared by both throws, because
Extrude fails through build_sketch_face and Revolve through build_sketch_wire — enriching
only one would have left the commoner path the less informative one.

Kernel 66115 assertions / 608 cases green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011FbJKJAJxxkhDTs9XdZzKA
This commit is contained in:
Tommaso Bianchi
2026-09-02 14:58:05 +02:00
co-authored by Claude Opus 5
parent 8b568b7b9d
commit bb6a1810f6
6 changed files with 231 additions and 32 deletions
+24 -8
View File
@@ -4703,14 +4703,23 @@ TEST_CASE("bridge round-trip serialization", "[CadDocument][bridge]")
using Catch::Matchers::WithinAbs;
CadDocument doc;
// The two collinear stubs plus the bridge span (0,0)->(30,0); the remaining three lines
// return to the origin so the profile is genuinely CLOSED. It used to be just the two
// stubs and the bridge, an entirely open chain that "extruded" only because OCCT will
// make a face out of an open wire — the silently-wrong geometry this area exists to stop.
// This test is about the bridge's serialization round-trip, and deserialize_recipe
// recomputes, so the document has to be one that legitimately builds.
std::vector<SketchEntity> ents = {
{SketchEntity::Type::Line, Vec2d(0,0), Vec2d(10,0)},
{SketchEntity::Type::Line, Vec2d(20,0), Vec2d(30,0)},
{SketchEntity::Type::Line, Vec2d(0,0), Vec2d(10,0)},
{SketchEntity::Type::Line, Vec2d(20,0), Vec2d(30,0)},
{SketchEntity::Type::Line, Vec2d(30,0), Vec2d(30,10)},
{SketchEntity::Type::Line, Vec2d(30,10), Vec2d(0,10)},
{SketchEntity::Type::Line, Vec2d(0,10), Vec2d(0,0)},
};
int sk = doc.add_sketch_entities(ents, SketchPlane::XY(), "S");
REQUIRE(sk == 0);
int bi = doc.add_bridge(sk, 0, 1, 1, 0, "Bridge");
REQUIRE(bi == 2);
REQUIRE(bi == 5);
doc.add_extrude(sk, 5.0, false, BooleanMode::New, "Extrude");
REQUIRE(doc.recompute());
@@ -4721,7 +4730,7 @@ TEST_CASE("bridge round-trip serialization", "[CadDocument][bridge]")
REQUIRE(doc2.deserialize_recipe(blob));
REQUIRE(doc2.features.size() == 2);
const auto& br = doc2.features[0].entities[2];
const auto& br = doc2.features[0].entities[5];
REQUIRE(br.type == SketchEntity::Type::BSpline);
REQUIRE(br.ctrl.size() == 4);
REQUIRE_THAT(br.ctrl.front().x(), WithinAbs(10.0, 1e-9));
@@ -7484,14 +7493,21 @@ TEST_CASE("An entity sketch that forms no wire fails instead of extruding a defa
Catch::Matchers::WithinRel(M_PI * 100.0 * 5.0, 0.01));
}
SECTION("circle + stray line is rejected, not silently turned into a box") {
// Behaviour CHANGED 2026-09-02 by Tommaso's decision. This used to require a refusal,
// because back then ignoring the stray meant falling through to a default rectangle — a
// box the user never drew. That fallback is gone: the closed profile is now built and the
// stray open chain is discarded, exactly as the viewport's region_loops already discards
// open chains when it decides what is extrudable. A stray click must not break a model
// that looks perfect on screen.
SECTION("circle + stray line builds the circle and ignores the stray") {
CadDocument doc;
int sk = doc.add_sketch_entities({ circle({0, 0}, 10.0), line({40, 40}, {60, 40}) },
SketchPlane::XY(), "Sketch");
doc.add_extrude(sk, 5.0, false, BooleanMode::New, "Extrude");
CHECK_FALSE(doc.recompute());
CHECK(doc.error.find("does not bound a face") != std::string::npos);
CHECK(doc.bodies.empty());
REQUIRE(doc.recompute());
CHECK(doc.error.empty());
CHECK_THAT(doc.body_mass_properties(0).volume,
Catch::Matchers::WithinRel(M_PI * 100.0 * 5.0, 0.01));
}
SECTION("two disjoint circles are rejected too") {