SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Section Analysis: a construction plane in a moved component cuts where it is drawn (#12582)
Danielb9270a6884ac
diff --git a/crates/engine/src/cmd/section.rs b/crates/engine/src/cmd/section.rsindex 54dcd97361..e1e7a229e8 100644--- a/crates/engine/src/cmd/section.rs+++ b/crates/engine/src/cmd/section.rs@@ -38,11 +38,12 @@ fn section(s: &mut Session, p: &Value) -> Result<Value> {let axis = [normal.x, normal.y, normal.z].iter().position(|c| c.abs() > 0.5);(pl.origin, normal, axis)}- // A construction plane (name or id): where it is now.+ // A construction plane (name or id): where it stands in the world, its component placed,+ // as the viewport draws it. The cut and the reply are in the world.Some(v @ (Value::String(_) | Value::Number(_))) => {let r = super::features::plane_param(s, Some(v), cmd)?;let solidcraft_doc::PlaneRef::Construction { feature } = &r else { return Err(bad(cmd, "`plane` must be a plane")) };- let st = s.model.state();+ let st = s.world_state()?;let c = st.construct.iter()diff --git a/crates/engine/src/construct_tests.rs b/crates/engine/src/construct_tests.rsindex da4cf75e1f..2ae063c7af 100644--- a/crates/engine/src/construct_tests.rs+++ b/crates/engine/src/construct_tests.rs@@ -621,6 +621,27 @@ fn construction_lives_in_the_component_frame() {assert!(near(point(&s, "PinTop"), Vec3::new(50.0, 20.0, 10.0)), "{:?}", point(&s, "PinTop"));}+/// A construction plane in a moved (and turned) component sections where the viewport draws it,+/// not where the component was modelled: the plane halves the box's height, which the turn+/// about X laid along Y.+#[test]+fn a_section_on_a_construction_plane_cuts_where_the_component_stands() {+ let mut s = Session::default();+ run(&mut s, "component.create", json!({"name": "Part", "grounded": false}));+ run(&mut s, "solid.box", json!({"length": 20, "width": 20, "height": 10}));+ run(&mut s, "construct.plane.offset", json!({"base": "XY", "offset": 5, "name": "Mid"}));+ run(&mut s, "occurrence.move", json!({"occurrence": "Part:1", "translate": [0, 0, 30], "axis": [1, 0, 0], "angle": "90 deg"}));+ // The box as `inspect.measure` answers it, placed in the world.+ let bbox = run(&mut s, "inspect.measure", json!({}))["bodies"][0]["bbox"].clone();+ let mid_y = (bbox["min"][1].as_f64().unwrap() + bbox["max"][1].as_f64().unwrap()) / 2.0;+ assert!(mid_y.abs() > 1.0, "the turn moved the box's middle off y = 0: {bbox}");+ let r = run(&mut s, "inspect.section", json!({"plane": "Mid"}));+ let y = r["section"]["origin"][1].as_f64().unwrap();+ assert!((y - mid_y).abs() < 1e-9, "the cut halves the placed box: {r}");+ let n = &r["section"]["normal"];+ assert!((n[1].as_f64().unwrap().abs() - 1.0).abs() < 1e-9 && n[2].as_f64().unwrap().abs() < 1e-9, "the normal turned with the box: {r}");+}+#[test]fn plane_perpendicular_to_a_plane_through_a_line() {let mut s = part();