SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Pattern of a join that merged its targets keeps working (#3378) (#3387)
denelson1-dot30e0db1e0597
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rsindex fdea27a9ca..30a7599a4c 100644--- a/crates/doc/src/eval.rs+++ b/crates/doc/src/eval.rs@@ -4689,6 +4689,11 @@ fn replay(// 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 };+ // A join that merged its targets left only the first of them (the others now live in+ // it): the copies change the bodies still there (#3378). When none is, the names stay+ // and say which body is missing.+ let present: Vec<String> = targets.iter().filter(|t| st.bodies.iter().any(|b| &b.name == *t)).cloned().collect();+ let targets = if present.is_empty() { targets } else { present };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), sodiff --git a/crates/engine/src/cmd/patterns_tests.rs b/crates/engine/src/cmd/patterns_tests.rsindex 97603e7a84..4d4a7e56f3 100644--- a/crates/engine/src/cmd/patterns_tests.rs+++ b/crates/engine/src/cmd/patterns_tests.rs@@ -549,3 +549,29 @@ fn copies_of_a_primitive_cut_only_its_targets() {assert!(rel(removed, holes * PI * 9.0 * 10.0) < 1e-3, "{id}: {removed} mm³ cut from Plaque");}}++/// #3378: a pattern or mirror of a join whose targets the join merged into one body copies onto+/// that body, as before #2755, instead of looking for the target the join used up.+#[test]+fn copies_of_a_join_that_merged_its_targets_join_the_merged_body() {+ for (copy, n) in [+ (json!(["solid.pattern.circular", {"features": ["spoke"], "axis": "Y", "count": 5}]), 5.0),+ (json!(["solid.mirror", {"features": ["spoke"], "plane": {"origin": [0, 0, 0], "normal": [1, 0, 0]}}]), 2.0),+ ] {+ let mut s = Session::default();+ run(&mut s, "solid.cylinder", json!({"radius": 66, "height": 3, "base": [0, 0, 0], "axis": "Y", "body_name": "rim"}));+ run(&mut s, "solid.cylinder", json!({"radius": 63, "height": 3, "base": [0, 0, 0], "axis": "Y", "operation": "cut", "targets": ["rim"]}));+ run(&mut s, "solid.cylinder", json!({"radius": 12, "height": 3, "base": [0, 0, 0], "axis": "Y", "body_name": "hub"}));+ let v0 = volume(&mut s);+ let spoke = json!({"length": 52, "width": 3, "height": 2.5, "corner": [12, 0, -1.25], "operation": "join", "targets": ["rim", "hub"], "name": "spoke"});+ run(&mut s, "solid.box", spoke);+ let v1 = volume(&mut s);+ let (id, p) = (copy[0].as_str().unwrap_or_default(), copy[1].clone());+ run(&mut s, id, p);+ let names = run(&mut s, "inspect.measure", json!({}))["bodies"].as_array().map(|b| b.iter().map(|x| x["name"].clone()).collect::<Vec<_>>());+ assert_eq!(names, Some(vec![json!("rim")]), "{id}: one body, the merged rim and hub");+ // Every copy adds what the seed spoke added (curved bodies measure to about 0.02 %; a+ // missing or doubled spoke is about 5 %).+ assert!(rel(volume(&mut s), v0 + n * (v1 - v0)) < 1e-3, "{id}: {} vs {}", volume(&mut s), v0 + n * (v1 - v0));+ }+}