A subtraction that removes nothing is an error, not a silent success

A boolean cut whose tool misses the target is a perfectly legal
operation: OCCT reports IsDone(), the shape comes back unchanged, and the
feature lands in the recipe reporting ok:true. Driving the MCP socket,
that produced two consecutive {ok: true, bodies: 1, error: ''} responses
for a hole that was never drilled -- same viewport, same 46939.11 mm3 --
and the tree grew two Hole features that will never cut anything. A
caller, an agent especially, has no signal at all that the thing it asked
for did not happen.

Measure the volume across the op in route_feature's in-place branch and
refuse the no-op. Only for removals: Hole, Thread, and Extrude / Revolve
/ Sweep / Loft in Cut mode. Everything else may legitimately leave the
volume alone -- a Transform certainly does. The tolerance is relative,
because an absolute epsilon is wrong across the mm-to-metre range of real
parts, and a cut that shaves a numerically invisible sliver is a miss
too. The existing rollback in the MCP actions already preserves the
reason, so a missed hole now answers ok:false with the error and undoes
the feature.

The confusion underneath was not itself a bug: hole's x/y are in the
sketch plane's frame, whose origin is describe_scene's modeling_origin,
and describe_tools documented them only as "number, unit mm". Passing the
world centre put the hole 135 mm clear of the solid. All six x/y params
on hole / hole_styled / hole_standard now say which frame they are in,
since the wrong guess was silent.

Regression test drives the reported failure directly: a hole at x=135 on
a 20x20x20 box is rejected and leaves the body untouched, the same hole
at the origin still removes exactly pi*4^2*20, and a cut-mode extrude
whose profile sits at x=200 is rejected too. 152 cases / 2083 assertions
green on both forks.

snaporca-daf.
This commit is contained in:
Tommaso Bianchi
2026-07-27 07:21:06 +02:00
parent 5d05ca30ca
commit 5f1811c2c5
3 changed files with 94 additions and 6 deletions
+55
View File
@@ -6697,3 +6697,58 @@ TEST_CASE("Failed sketch solve leaves geometry untouched", "[CadDocument]")
CHECK((ents[b].p1 - ents[xi].p1).norm() == Approx(0.0).margin(1e-6));
}
}
// A subtraction whose tool misses the target is a perfectly legal boolean that removes nothing,
// so OCCT reports success and the feature lands in the recipe with ok:true and an unchanged body.
// That is how a hole placed with world coordinates instead of plane-frame ones read as "drilled"
// three times in a row while the volume never moved. snaporca-daf.
TEST_CASE("A cut that removes no material is an error, not a silent success", "[CadDocument]")
{
// 20 x 20 box, 20 tall, centred on the origin of the XY plane.
auto box = [] {
CadDocument d;
int sk = d.add_sketch(SketchShape::Rectangle, SketchPlane::XY(), 20, 20, 10, "Sketch");
d.add_extrude(sk, 20.0, false, BooleanMode::New, "Extrude");
return d;
};
SECTION("hole placed clear of the body is rejected") {
CadDocument doc = box();
REQUIRE(doc.recompute());
const double solid = doc.body_mass_properties(0).volume;
// 135 mm away — exactly the failure the issue reported (world centre passed for a
// plane-frame coordinate). The old behaviour: recompute() true, volume unchanged.
doc.add_hole(8.0, 20.0, true, 135.0, 0.0, SketchPlane::XY(), "Hole");
CHECK_FALSE(doc.recompute());
CHECK(doc.error.find("removed no material") != std::string::npos);
// And the body is left as it was, not half-applied.
CadDocument again = box();
REQUIRE(again.recompute());
CHECK(again.body_mass_properties(0).volume == Approx(solid).margin(1e-6));
}
SECTION("the same hole on the body still works") {
CadDocument doc = box();
REQUIRE(doc.recompute());
const double solid = doc.body_mass_properties(0).volume;
doc.add_hole(8.0, 20.0, true, 0.0, 0.0, SketchPlane::XY(), "Hole");
REQUIRE(doc.recompute());
CHECK(doc.body_mass_properties(0).volume
== Approx(solid - M_PI * 16.0 * 20.0).epsilon(0.01));
}
SECTION("a cut-mode extrude that misses is rejected too") {
CadDocument doc = box();
REQUIRE(doc.recompute());
// Same trick, on the sketch plane's origin: the profile sits far outside the box,
// so the subtraction is a legal no-op.
SketchPlane far_plane = SketchPlane::XY();
far_plane.origin = Vec3d(200.0, 0.0, 0.0);
int sk = doc.add_sketch(SketchShape::Rectangle, far_plane, 5, 5, 10, "Tool");
doc.add_extrude(sk, 30.0, false, BooleanMode::Cut, "Cut");
CHECK_FALSE(doc.recompute());
CHECK(doc.error.find("removed no material") != std::string::npos);
}
}