From ebada963a4b7d686f04554051df523545a7fcb93 Mon Sep 17 00:00:00 2001 From: jb69 Date: Tue, 20 Oct 2026 11:43:10 +0000 Subject: [PATCH] Parameters: walk through a flipped plane to its base's expressions (#3481) `PlaneRef::walk_exprs` stopped at `Flipped`, so a sketch created with `flip` on an offset plane (`{plane: "XZ", offset: "d", flip: "x"}`) did not list the offset as an input. Changing `d` rebuilt nothing that read the sketch, and the model went stale. `Flipped` now continues to its base, as `Offset` and `AtAngle` do, in both `walk_exprs` and `walk_exprs_mut`. Test: a loft between XZ and a flipped XZ plane offset by `d` has the volume for d = 30, and for d = 50 after `parameters.change`. Co-authored-by: Claude Opus 5.5 --- crates/doc/src/walk.rs | 6 ++++++ crates/engine/src/cmd/parameters_tests.rs | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/crates/doc/src/walk.rs b/crates/doc/src/walk.rs index fa09250a5..aabbf8a8b 100644 --- a/crates/doc/src/walk.rs +++ b/crates/doc/src/walk.rs @@ -332,6 +332,9 @@ impl Walk for PlaneRef { p = base; } PlaneRef::AlongPath { t, .. } => return f(("Distance (0 to 1)", t, Kind::Unitless, ExprRole::Input)), + // A plane seen from behind keeps its base's expressions (a sketch made with + // `flip` on an offset plane did not follow the offset's parameter). + PlaneRef::Flipped { base, .. } => p = base, PlaneRef::Placed { origin, .. } => { for (label, e) in ["X", "Y", "Z"].into_iter().zip(origin) { f((label, e, Kind::Length, ExprRole::Placement)); @@ -355,6 +358,9 @@ impl Walk for PlaneRef { p = base; } PlaneRef::AlongPath { t, .. } => return f(("Distance (0 to 1)", t, Kind::Unitless, ExprRole::Input)), + // A plane seen from behind keeps its base's expressions (a sketch made with + // `flip` on an offset plane did not follow the offset's parameter). + PlaneRef::Flipped { base, .. } => p = base, PlaneRef::Placed { origin, .. } => { for (label, e) in ["X", "Y", "Z"].into_iter().zip(origin) { f((label, e, Kind::Length, ExprRole::Placement)); diff --git a/crates/engine/src/cmd/parameters_tests.rs b/crates/engine/src/cmd/parameters_tests.rs index 66a88f1ab..422b3cfd6 100644 --- a/crates/engine/src/cmd/parameters_tests.rs +++ b/crates/engine/src/cmd/parameters_tests.rs @@ -655,3 +655,21 @@ fn several_parameters_change_in_one_rebuild_and_one_undo() { assert_eq!((expr_of(&mut s, "len"), expr_of(&mut s, "h")), ("60 mm".to_string(), "10 mm".to_string())); assert!(rel(volume(&mut s), 40.0 * 30.0 * 10.0) < 1e-9); } + +/// A sketch made with `flip` on an offset plane follows the offset's parameter (the parameter +/// walk stopped at the flipped plane, so a change rebuilt nothing). +#[test] +fn flipped_offset_sketch_plane_follows_its_parameter() { + let mut s = Session::default(); + run(&mut s, "parameters.add", json!({"name": "d", "expression": "30 mm"})); + run(&mut s, "sketch.create", json!({"plane": "XZ", "name": "Near"})); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-10, -10], "p1": [10, 10]})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "sketch.create", json!({"plane": "XZ", "offset": "d", "flip": "x", "name": "Far"})); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-10, -10], "p1": [10, 10]})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "solid.loft", json!({"sections": [{"sketch": "Near"}, {"sketch": "Far"}]})); + assert!((volume(&mut s) - 400.0 * 30.0).abs() < 1e-6); + run(&mut s, "parameters.change", json!({"name": "d", "expression": "50 mm"})); + assert!((volume(&mut s) - 400.0 * 50.0).abs() < 1e-6, "{}", volume(&mut s)); +}