Edit Offset Plane: keep a face base, refuse a plane on itself (#3567) (#3889)

* claim: #3567

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

* Edit Offset Plane: keep a face base, refuse a plane on itself (#3567)

Reopening an Offset Plane built on a face looked the face up at the
plane's origin, which can lie off the face, so the Plane input came up
empty. Look it up at the point picked on the face. A redefine that
builds a feature on itself is refused with a plain message instead of
failing with "plane offsets nested too deeply".

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LoohiandClaude Opus 5.5 authored and GitHub committed 2026-10-22 18:30:02 +00:00
1 parent 46f80b769f
commit aaa110218b
5 files changed
+60 -1

No files matched your search

+12
View File
@@ -28,6 +28,18 @@ impl FeatureKind {
v
}
/// Whether the feature names the feature `name` (the construction plane a plane is built on,
/// a patterned or mirrored feature).
pub fn names_feature(&self, name: &str) -> bool {
let mut found = false;
self.walk_refs(&mut |r| {
if let Ref::Feature(n) = r {
found |= n.as_ref() == name;
}
});
found
}
/// Point references to sketches (by id) and features (by name) at their copies, or at a
/// feature's new name (`timeline.rename`).
pub fn remap_refs(&mut self, sketches: &BTreeMap<u64, u64>, names: &BTreeMap<String, String>) {
+5
View File
@@ -1253,6 +1253,11 @@ fn redefine(s: &mut Session, p: &Value) -> Result<Value> {
if std::mem::discriminant(&new.kind) != std::mem::discriminant(&old.kind) && !(boundary(&new.kind) && boundary(&old.kind)) {
return Err(bad(cmd, format!("{} is not a {} feature", old.name, cid)));
}
// The trial still holds the old feature, so a plane offset from its own name was made there,
// and once swapped in it would be built on itself (#3567).
if new.kind.names_feature(&old.name) {
return Err(bad(cmd, format!("{} can't be built on itself: pick another plane or face", old.name)));
}
// Optional inputs can move other inputs' positions (e.g. Distance 2 goes before Taper).
// Keep each existing model parameter attached to its semantic input, rather than its
// old index. Constructor-assigned names for new inputs cannot reuse the old dimensions.
@@ -80,3 +80,22 @@ fn offset_plane_rejects_bad_face_picks_without_panicking() {
assert_eq!(s.doc.features.len(), features, "{base}");
}
}
/// #3567: an Offset Plane redefined with itself as its base was accepted while the old plane
/// stood beside the new one, and then failed with "plane offsets nested too deeply". It is
/// refused with a plain message, and the plane is left as it was.
#[test]
fn offset_plane_redefined_on_itself_is_refused() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": 20, "corner": [10, 0, 0]}));
run(&mut s, "construct.plane.offset", json!({"base": {"face": [30, 0, 10]}, "offset": 10, "name": "Side"}));
assert!((plane(&s, "Side").origin.y + 10.0).abs() < 1e-9, "{:?}", plane(&s, "Side"));
let saved = s.doc.to_json();
let redefine = |base: Value| json!({"feature": "Side", "command": "construct.plane.offset", "params": {"base": base, "offset": "7"}});
let e = s.execute("timeline.redefine", &redefine(json!("Side"))).unwrap_err().to_string();
assert!(e.contains("can't be built on itself"), "{e}");
assert_eq!(s.doc.to_json(), saved);
// The same edit on the face it was built on works.
run(&mut s, "timeline.redefine", redefine(json!({"face": [30, 0, 10]})));
assert!((plane(&s, "Side").origin.y + 7.0).abs() < 1e-9, "{:?}", plane(&s, "Side"));
}
+3 -1
View File
@@ -4114,7 +4114,9 @@ pub(crate) fn plane_sel(s: &Session, pl: &PlaneRef) -> Option<Sel> {
match pl {
PlaneRef::Origin { name } => Some(Sel::Plane { name: name.clone() }),
PlaneRef::Construction { name } => Some(Sel::Plane { name: name.to_string() }),
PlaneRef::Custom { plane } | PlaneRef::Face { plane, .. } => face_sel(s, plane.origin),
PlaneRef::Custom { plane } => face_sel(s, plane.origin),
// The point picked on the face: the plane's origin can lie off the face (#3567).
PlaneRef::Face { at, .. } => face_sel(s, *at),
PlaneRef::Flipped { base, .. } => plane_sel(s, base),
_ => None,
}
+21
View File
@@ -85,6 +85,27 @@ fn feature_mirror_and_patterns_reopen_as_feature_replays_even_for_body_creators(
}
}
/// #3567: an Offset Plane built on a face reopened with its Plane input empty when the face's
/// plane origin lay off the face (here the world origin's foot, beside the box), so OK asked to
/// pick a plane first. It reopens with the face, and OK keeps the plane on it.
#[test]
fn offset_plane_on_a_face_reopens_with_the_face() {
let mut app = app_with(json!([
{"command":"solid.box","params":{"length":40,"width":30,"height":20,"corner":[10,0,0],"body_name":"Plate"}},
{"command":"construct.plane.offset","params":{"base":{"face":[30,0,10]},"offset":10,"name":"Side"}}
]));
let side = app.session.doc.find_feature("Side").unwrap().clone();
let d = crate::dialogs::for_feature(&app, side.id, None).unwrap();
assert!(matches!(d.inputs[0].items.as_slice(), [Sel::Face { body, .. }] if body == "Plate"), "{:?}", d.inputs[0].items);
let (edit, p) = apply_commands(&app, &d).unwrap().remove(0);
assert_eq!(edit, "timeline.redefine");
app.session.execute(&edit, &p).unwrap();
assert!(app.session.model.results.iter().all(|r| r.error.is_none()), "{:?}", app.session.model.results);
let state = app.session.model.state();
let plane = state.construct.iter().find(|c| c.name == "Side").map(|c| c.geom.clone());
assert!(matches!(plane, Some(solidcraft_engine::doc::construct::ConstructGeom::Plane(pl)) if (pl.origin.y + 10.0).abs() < 1e-9), "{plane:?}");
}
#[test]
fn feature_pattern_controls_preview_without_committing_and_cancel_cleanly() {
for command in ["solid.pattern.rectangular", "solid.pattern.circular"] {