Construction: the root's constructions are found once the design has a component (#6219)

* Test: a plane through a construction axis follows it in a design with a component

Two offset planes, the axis where they meet and a plane through that axis. Once the design has a
component, a parameter change fails the last plane with "unknown construction `Ax`".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PsiqyXWBFGTCX9J51bhysc

* Construction: the root's constructions are found once the design has a component

Problem: once a design has a component, the root's construction features are built in the model
placed in the world. That state carried each component's bodies, sketches and threads, but not
its construction planes, axes and points, so a construction built on another one failed on every
evaluation with "unknown construction".

Solution: the world state carries each component's constructions where the component is placed
(moved by its occurrence's placement, as the bodies are).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PsiqyXWBFGTCX9J51bhysc

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NOWN-DEV
2026-10-25 01:55:56 +00:00
committed by GitHub
parent 5d37cb01d5
commit c242c484a8
3 changed files with 42 additions and 3 deletions
+12
View File
@@ -99,6 +99,18 @@ pub enum ConstructGeom {
Point(Vec3),
}
impl ConstructGeom {
/// The geometry moved by `m` (where its component is placed).
pub fn placed(&self, m: &crate::Mat) -> ConstructGeom {
let (point, vector) = (|p: Vec3| crate::apply_point(m, p), |v: Vec3| crate::apply_vector(m, v));
match self {
ConstructGeom::Plane(p) => Plane::new(point(p.origin), vector(p.x), vector(p.y)).map_or_else(|| self.clone(), ConstructGeom::Plane),
ConstructGeom::Axis { origin, dir } => ConstructGeom::Axis { origin: point(*origin), dir: vector(*dir) },
ConstructGeom::Point(p) => ConstructGeom::Point(point(*p)),
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Construct {
pub feature: u64,
+11 -3
View File
@@ -7717,9 +7717,10 @@ pub fn state_in_frame_at<'a>(doc: &Document, st: &'a ModelState, comp: u64, fram
Cow::Owned(out)
}
/// The model placed in the world: each component's bodies, sketches and threads through every
/// occurrence of it (bodies of the first placement keep their names; further instances get the
/// occurrence path in brackets). Without components this is the model itself.
/// The model placed in the world: each component's bodies, sketches, threads and construction
/// geometry through every occurrence of it (bodies of the first placement keep their names;
/// further instances get the occurrence path in brackets). Without components this is the model
/// itself.
pub fn world_state(doc: &Document, st: &ModelState) -> ModelState {
world_state_reusing(doc, st, &mut PlacedBodies::default())
}
@@ -7939,6 +7940,13 @@ pub fn world_state_reusing(doc: &Document, st: &ModelState, placed_before: &mut
}
out.sketches.push(Arc::new(s2));
}
// The component's construction planes, axes and points where it is placed: once the
// design has a component the root's constructions are built in this state
// (`construction_state`), and one built on another finds it here by name.
for c in st.construct.iter().filter(|c| comp_of_feature(c.feature) == comp) {
let geom = if ident { c.geom.clone() } else { c.geom.placed(&m) };
out.construct.push(crate::construct::Construct { geom, ..c.clone() });
}
for t in st
.threads
.iter()
+19
View File
@@ -312,6 +312,25 @@ fn plane_on_a_3d_wire_moves_with_its_component() {
assert!(parallel(p.normal(), Vec3::Z));
}
/// Once a design has a component, the root's constructions are built in the model placed in the
/// world. A plane through a construction axis of the root finds the axis there and follows it
/// (it failed with "unknown construction `Ax`" on every evaluation after the component came).
#[test]
fn a_plane_through_a_construction_axis_follows_it_in_a_design_with_a_component() {
let mut s = Session::default();
run(&mut s, "parameters.add", json!({"name": "d", "expression": "10 mm"}));
run(&mut s, "construct.plane.offset", json!({"base": "XZ", "offset": "d", "name": "P1"}));
run(&mut s, "construct.plane.offset", json!({"base": "XY", "offset": "5 mm", "name": "P2"}));
run(&mut s, "construct.axis.two_planes", json!({"a": {"plane": "P1"}, "b": {"plane": "P2"}, "name": "Ax"}));
run(&mut s, "construct.plane.perpendicular", json!({"plane": "XY", "line": {"axis": "Ax"}, "name": "Q"}));
run(&mut s, "component.create", json!({"name": "Part"}));
run(&mut s, "parameters.change", json!({"name": "d", "expression": "30 mm"}));
let errors: Vec<String> = s.model.results.iter().filter_map(|r| r.error.clone()).collect();
assert!(errors.is_empty(), "{errors:?}");
let q = plane(&s, "Q");
assert!(on_plane(&q, Vec3::new(0.0, 30.0, 5.0)) && parallel(q.normal(), Vec3::Y), "{q:?}");
}
/// Built from model geometry, they follow when the model changes: the box gets taller.
#[test]
fn construction_follows_the_model() {