SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Thread: a modelled thread on one hole breaks the next hole (#11367) (#12491)
Homero Thompson850509120b9d
diff --git a/crates/doc/src/eval_thread.rs b/crates/doc/src/eval_thread.rsindex 9490817afe..8d434ac4d5 100644--- a/crates/doc/src/eval_thread.rs+++ b/crates/doc/src/eval_thread.rs@@ -1122,4 +1122,31 @@ mod tests {// The square stop leaves about half a pitch's worth of groove uncut: well over a mm³.assert!(square > trimmed + 1.0, "{square} vs {trimmed}");}++ /// A modelled thread on one hole leaves the other hole's wall a cylinder to thread: the+ /// second hole still takes its thread (#11367).+ ///+ /// The modelled thread cuts the body, and the cut must not take the body's other cylinders+ /// with it: the second hole's wall is still a cylinder, so it still takes a thread, modelled+ /// or cosmetic.+ #[test]+ fn a_modelled_thread_leaves_the_next_hole_a_cylinder_to_thread() {+ // An 80 x 80 x 20 mm block with two 5 mm holes.+ let block = kernel::box_solid(Vec3::new(-40.0, -40.0, 0.0), Vec3::new(40.0, 40.0, 20.0)).unwrap();+ let hole = |x: f64| kernel::cylinder(Vec3::new(x, 0.0, -1.0), Vec3::new(0.0, 0.0, 1.0), 2.5, 22.0).unwrap();+ let mut body = kernel::boolean(&block, &hole(-20.0), BoolOp::Cut).unwrap().unwrap();+ body = kernel::boolean(&body, &hole(20.0), BoolOp::Cut).unwrap().unwrap();+ let mut st = ModelState::default();+ st.bodies.push(ModelBody::new("Part".into(), body, 1));+ let ask = ThreadAsk { designation: Some("M6"), ..ask() };+ // The first hole takes a modelled M6 thread.+ let on = thread_on(&st, 1, Vec3::new(-17.5, 0.0, 10.0), &ask).unwrap();+ cut(&mut st, on, (ThreadTip::None, None, None)).unwrap();+ // The second hole's wall is still a cylinder: it takes a thread too.+ let on = thread_on(&st, 1, Vec3::new(22.5, 0.0, 10.0), &ask);+ assert!(on.is_ok(), "the second hole still has a cylinder to thread: {:?}", on.err());+ // And a modelled one cuts there as well.+ let on = thread_on(&st, 1, Vec3::new(22.5, 0.0, 10.0), &ask).unwrap();+ assert!(cut(&mut st, on, (ThreadTip::None, None, None)).is_ok());+ }}diff --git a/crates/engine/src/thread_tests.rs b/crates/engine/src/thread_tests.rsindex 9975f7f7ed..25e90a5e69 100644--- a/crates/engine/src/thread_tests.rs+++ b/crates/engine/src/thread_tests.rs@@ -1506,3 +1506,25 @@ fn editing_a_saved_automatic_thread_keeps_its_old_size() {run(&mut s, "timeline.redefine", json!({"feature": made["feature"], "command": "solid.thread", "params": {"face": [6, 0, 10], "hand": "left"}}));assert_eq!(designations(&s), ["M14"]);}++/// #11367: a modelled thread on one hole must not stop the next hole's wall from being found+/// as a cylinder to thread. The cut the modelled thread makes must not take the body's other+/// cylinders with it: the second hole still takes a thread, modelled or cosmetic.+#[test]+fn a_modelled_thread_leaves_the_next_hole_a_cylinder_to_thread() {+ for gap in [40.0, 20.0, 12.0, 8.0] {+ let mut s = Session::default();+ run(&mut s, "solid.box", json!({"corner": [0, 0, 0], "length": 80, "width": 80, "height": 20, "body_name": "Blk"}));+ run(&mut s, "solid.hole", json!({"position": [20, 40, 20], "diameter": 5, "direction": [0, 0, -1]}));+ run(&mut s, "solid.hole", json!({"position": [20.0 + gap, 40.0, 20.0], "diameter": 5, "direction": [0, 0, -1]}));+ // The first hole takes a modelled M6 thread.+ let t1 = s.execute("solid.thread", &json!({"face": [22.5, 40.0, 10.0], "designation": "M6", "modeled": true}));+ assert!(t1.is_ok(), "gap {gap}: the first hole takes its thread: {t1:?}");+ // The second hole's wall is still a cylinder: it takes a cosmetic thread...+ let t2 = s.execute("solid.thread", &json!({"face": [22.5 + gap, 40.0, 10.0], "designation": "M6"}));+ assert!(t2.is_ok(), "gap {gap}: the second hole still has a cylinder to thread: {t2:?}");+ // ...and a modelled one.+ let t3 = s.execute("solid.thread", &json!({"face": [22.5 + gap, 40.0, 10.0], "designation": "M6", "modeled": true}));+ assert!(t3.is_ok(), "gap {gap}: the second hole takes a modelled thread: {t3:?}");+ }+}