SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Circular Pattern of a cut works with another component active (#12996) (#13145)
dudedagger42778e7465e94b
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rsindex 5c0721d5c5..53362a765b 100644--- a/crates/doc/src/eval.rs+++ b/crates/doc/src/eval.rs@@ -7021,6 +7021,22 @@ fn replay(instances.push(start..copies.len());}}+ // A cut or intersect copy with no named targets, made where the pattern's own component+ // has no body for it, works on the bodies of its source's component, as the source did+ // (#12996). A pattern whose component has bodies cuts them, as before. The same scope+ // counts misses, takes sheet cuts and applies the copies.+ let scoped;+ let f = if matches!(op, Operation::Cut | Operation::Intersect)+ && targets.is_empty()+ && f.participants.is_empty()+ && src.component != f.component+ && !st.bodies.iter().any(|b| b.component == f.component || b.feature == f.id)+ {+ scoped = Feature { component: src.component, ..f.clone() };+ &scoped+ } else {+ f+ };if op == Operation::Cut {let (m, t) = count_copy_misses(st, f, &targets, &copies, &instances, &axes);missed += m;diff --git a/crates/engine/src/boolean_regression_tests.rs b/crates/engine/src/boolean_regression_tests.rsindex 57773fa9da..1af54cf79d 100644--- a/crates/engine/src/boolean_regression_tests.rs+++ b/crates/engine/src/boolean_regression_tests.rs@@ -1552,3 +1552,57 @@ fn join_that_meets_no_body_keeps_the_piece_and_says_so() {let combine = s.execute("solid.combine", &json!({"target": "A", "tools": ["B"], "operation": "join"})).unwrap();assert!(combine["warning"].is_null(), "{combine}");}++/// #12996: a circular pattern of an untargeted cut made in a component, run with another+/// component active, cuts the bodies of the cut's own component, as the cut did.+#[test]+fn pattern_of_an_untargeted_cut_in_a_component_works_with_root_active() {+ let mut s = Session::default();+ let run = |s: &mut Session, command: &str, params: Value| s.execute(command, ¶ms).unwrap();+ run(&mut s, "component.create", json!({"name": "Main Body"}));+ run(&mut s, "sketch.create", json!({"plane": "XY"}));+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-50, -50], "p1": [50, 50]}));+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "solid.extrude", json!({"distance": "20 mm", "operation": "new", "body_name": "Body1"}));+ run(&mut s, "sketch.create", json!({"plane": {"origin": [0, 0, 20], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}}));+ run(&mut s, "sketch.circle.center", json!({"center": [30, 0], "radius": 4}));+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "solid.extrude", json!({"distance": "10 mm", "direction": "negative", "operation": "cut", "name": "Extrude62"}));+ let one_hole = volume(&s, "Body1");+ run(&mut s, "component.activate", json!({"component": "root"}));+ run(&mut s, "component.create", json!({"name": "Other"}));+ run(&mut s, "solid.pattern.circular", json!({"features": ["Extrude62"], "axis": "Z", "count": 10}));+ let hole = 10.0 * 16.0 * std::f64::consts::PI;+ let got = volume(&s, "Body1");+ assert!((one_hole - got - 9.0 * hole).abs() < 0.02 * hole, "{one_hole} -> {got}");+}++/// #12996: when the component active for the pattern has a body of its own, the copies of an+/// untargeted cut keep cutting it, as they did before: saved designs rebuild the same.+#[test]+fn pattern_of_an_untargeted_cut_still_cuts_its_own_components_body() {+ let mut s = Session::default();+ let run = |s: &mut Session, command: &str, params: Value| s.execute(command, ¶ms).unwrap();+ run(&mut s, "component.create", json!({"name": "Main Body"}));+ run(&mut s, "sketch.create", json!({"plane": "XY"}));+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-50, -50], "p1": [50, 50]}));+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "solid.extrude", json!({"distance": "20 mm", "operation": "new", "body_name": "Body1"}));+ run(&mut s, "sketch.create", json!({"plane": {"origin": [0, 0, 20], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}}));+ run(&mut s, "sketch.circle.center", json!({"center": [30, 0], "radius": 4}));+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "solid.extrude", json!({"distance": "10 mm", "direction": "negative", "operation": "cut", "name": "Extrude62"}));+ let one_hole = volume(&s, "Body1");+ run(&mut s, "component.activate", json!({"component": "root"}));+ run(&mut s, "component.create", json!({"name": "Other"}));+ run(&mut s, "sketch.create", json!({"plane": "XY"}));+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-50, -50], "p1": [50, 50]}));+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "solid.extrude", json!({"distance": "20 mm", "operation": "new", "body_name": "Plate2"}));+ let plate = volume(&s, "Plate2");+ run(&mut s, "solid.pattern.circular", json!({"features": ["Extrude62"], "axis": "Z", "count": 10}));+ let hole = 10.0 * 16.0 * std::f64::consts::PI;+ let (body1, plate2) = (volume(&s, "Body1"), volume(&s, "Plate2"));+ assert!((one_hole - body1).abs() < 0.02 * hole, "Body1 untouched: {one_hole} -> {body1}");+ assert!((plate - plate2 - 9.0 * hole).abs() < 0.02 * hole, "Plate2 cut: {plate} -> {plate2}");+}