Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Pattern and Mirror copies of a primitive change only the seed's targets (#2755) (#2756)

rlartotaef13b52f4c7
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index 71e40fcc96..ca8773c4b3 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -4356,6 +4356,9 @@ fn replay(
continue;
}
let (op, targets) = feature_op(src);
+ // A primitive's or a hole's targets are its participants (#1108): the copies change
+ // those bodies only, like the feature itself (#2755).
+ let targets = if targets.is_empty() { src.participants.clone() } else { targets };
let mut copies = Vec::new();
if let FeatureKind::Hole { diameter, depth, hole, to, .. } = &src.kind {
// A hole is drilled again at each copy of its spot (found on the surface there), so
diff --git a/crates/engine/src/cmd/patterns_tests.rs b/crates/engine/src/cmd/patterns_tests.rs
index 0444c02aa4..97603e7a84 100644
--- a/crates/engine/src/cmd/patterns_tests.rs
+++ b/crates/engine/src/cmd/patterns_tests.rs
@@ -521,3 +521,31 @@ fn pattern_of_cuts_beside_a_round_needs_no_retries() {
let v = volume(&mut s);
assert!(rel(v, expected) < 1e-5, "{v} vs {expected}");
}
+
+/// #2755: a cut cylinder with `targets` cuts only those bodies, and so do its pattern and mirror
+/// copies: a body over the plate that the cylinder was told to leave alone keeps its volume.
+#[test]
+fn copies_of_a_primitive_cut_only_its_targets() {
+ let body_volume = |s: &mut Session, name: &str| {
+ let m = run(s, "inspect.measure", json!({"bodies": [name]}));
+ m["bodies"][0]["volume_mm3"].as_f64().unwrap_or(f64::NAN)
+ };
+ // The command, and the holes in the plate after it (the cylinder's and its copies).
+ for (copy, holes) in [
+ (json!(["solid.pattern.rectangular", {"features": ["Trou"], "dir1": [1, 0, 0], "count1": 3, "spacing1": 30}]), 3.0),
+ (json!(["solid.mirror", {"features": ["Trou"], "plane": {"origin": [50, 0, 0], "normal": [1, 0, 0]}}]), 2.0),
+ ] {
+ let mut s = Session::default();
+ run(&mut s, "solid.box", json!({"length": 100, "width": 60, "height": 10, "body_name": "Plaque"}));
+ run(&mut s, "solid.box", json!({"length": 100, "width": 60, "height": 10, "corner": [0, 0, 5], "operation": "new", "body_name": "Voisin"}));
+ let cyl = json!({"radius": 3, "height": 30, "base": [10, 10, -5], "operation": "cut", "targets": ["Plaque"], "name": "Trou"});
+ run(&mut s, "solid.cylinder", cyl);
+ assert!(rel(body_volume(&mut s, "Voisin"), 60000.0) < 1e-9);
+ let (id, p) = (copy[0].as_str().unwrap_or_default(), copy[1].clone());
+ let r = run(&mut s, id, p);
+ assert_eq!(r["changed_bodies"], json!(["Plaque"]), "{id}");
+ assert!(rel(body_volume(&mut s, "Voisin"), 60000.0) < 1e-9, "{id} cut Voisin");
+ let removed = 60000.0 - body_volume(&mut s, "Plaque");
+ assert!(rel(removed, holes * PI * 9.0 * 10.0) < 1e-3, "{id}: {removed} mm³ cut from Plaque");
+ }
+}