From 613903229e414ae2723016205eaaba95374e60e5 Mon Sep 17 00:00:00 2001 From: semmelrinde <124386289+semmelrinde@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:42:28 +0000 Subject: [PATCH] Patterns: copies of a To Object extrude follow the face it reaches (#2121) (#6093) A feature's face points are moved onto their named faces before it is evaluated, so a To Object extrude follows its target face when an earlier feature moves it. A pattern's or mirror's copies were built from the feature as stored, with the face where it was picked: after a gear's disc was made thicker, the tooth reached the new top but its pattern copies kept the old height. The copies now use the same moved points; the move is one helper used in both places. Co-authored-by: Claude Opus 5.5 --- crates/doc/src/eval.rs | 106 ++++++++++++++---------- crates/engine/src/cmd/patterns_tests.rs | 25 ++++++ 2 files changed, 85 insertions(+), 46 deletions(-) diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs index 4bac408da..4ff701cd3 100644 --- a/crates/doc/src/eval.rs +++ b/crates/doc/src/eval.rs @@ -2075,52 +2075,15 @@ impl Model { // Face references by name: move each face point onto its named face (on the body the // feature names, when it names one and the face is there). let renamed; - // Cylindrical emboss resolves its named face in the selected body's frame - // and certifies an analytic anchor; mesh projection here would undo that. - let explicit_emboss = matches!(&f.kind, FeatureKind::Emboss { face: Some(_), .. }); - let f = if !explicit_emboss && f.face_names.iter().any(|n| !n.is_empty()) { - let mut g = f.clone(); - let mut notes = Vec::new(); - // A hole's position is a place on its face, not a pick of the face: it follows - // the face along the hole's axis and never slides sideways to the face's nearest - // point when the face no longer reaches it. - let hole_axis = match &f.kind { - FeatureKind::Hole { direction, points: None | Some(crate::SketchPoints { single: true, .. }), .. } => direction.normalized(), - _ => None, - }; - let fst = face_point_state(doc, &state, &f.kind, f.component); - for (k, (p, n)) in g.kind.face_points_mut().into_iter().zip(&f.face_names).enumerate() { - if n.is_empty() { - continue; - } - match crate::name_lookup::locate_face_on_body(&fst, f.kind.face_body(), n, *p) { - Some(hit) => { - if let Some(note) = hit.note(n) { - notes.push(note); - } - match (k, hole_axis) { - (0, Some(axis)) => match hit.along(&fst, *p, axis) { - Some(q) => *p = q, - // The place still lies on the face (the axis may run along it). - None if hit.on_point => {} - None => notes.push(format!( - "the hole's position [{}, {}, {}] is no longer on face `{n}`: it stays where it was placed", - p.x, p.y, p.z - )), - }, - _ => *p = hit.point, - } - } - None => notes.push(format!("face `{n}` no longer exists; using the face at the picked point")), + let f = match with_named_face_points(doc, &state, f) { + Some((g, notes)) => { + if !notes.is_empty() { + warning = Some(notes.join("; ")); } + renamed = g; + &renamed } - if !notes.is_empty() { - warning = Some(notes.join("; ")); - } - renamed = g; - &renamed - } else { - f + None => f, }; // A parameter with an error fails the features using it, with that error. let bad_param = param_names(f).into_iter().find_map(|n| self.param_errors.get(&n).map(|e| format!("parameter `{n}`: {e}"))); @@ -6189,6 +6152,54 @@ fn copied_features(doc: &Document, vals: &BTreeMap, st: &ModelSta /// own sources, at each of its transforms moved by each of ours. Those copies are numbered after /// `mats`' own (which keep the numbers they always had), each nested source in a block of its /// own, so no two copies of one feature share an instance. Suppressed sources copy nothing. +/// `f` with each face point moved onto its named face (on the body the feature names, when it +/// names one and the face is there) in `state`, and notes for names that no longer find their +/// face. `None` when `f` names no face. +fn with_named_face_points(doc: &Document, state: &ModelState, f: &Feature) -> Option<(Feature, Vec)> { + // Cylindrical emboss resolves its named face in the selected body's frame + // and certifies an analytic anchor; mesh projection here would undo that. + let explicit_emboss = matches!(&f.kind, FeatureKind::Emboss { face: Some(_), .. }); + if explicit_emboss || !f.face_names.iter().any(|n| !n.is_empty()) { + return None; + } + let mut g = f.clone(); + let mut notes = Vec::new(); + // A hole's position is a place on its face, not a pick of the face: it follows + // the face along the hole's axis and never slides sideways to the face's nearest + // point when the face no longer reaches it. + let hole_axis = match &f.kind { + FeatureKind::Hole { direction, points: None | Some(crate::SketchPoints { single: true, .. }), .. } => direction.normalized(), + _ => None, + }; + let fst = face_point_state(doc, state, &f.kind, f.component); + for (k, (p, n)) in g.kind.face_points_mut().into_iter().zip(&f.face_names).enumerate() { + if n.is_empty() { + continue; + } + match crate::name_lookup::locate_face_on_body(&fst, f.kind.face_body(), n, *p) { + Some(hit) => { + if let Some(note) = hit.note(n) { + notes.push(note); + } + match (k, hole_axis) { + (0, Some(axis)) => match hit.along(&fst, *p, axis) { + Some(q) => *p = q, + // The place still lies on the face (the axis may run along it). + None if hit.on_point => {} + None => notes.push(format!( + "the hole's position [{}, {}, {}] is no longer on face `{n}`: it stays where it was placed", + p.x, p.y, p.z + )), + }, + _ => *p = hit.point, + } + } + None => notes.push(format!("face `{n}` no longer exists; using the face at the picked point")), + } + } + Some((g, notes)) +} + fn copy_plan<'a>( doc: &'a Document, vals: &BTreeMap, @@ -6375,8 +6386,11 @@ fn replay( } } } else { - // Each copy's faces are named as the source feature's, with the instance. - let tools = feature_tools_with_constructor(doc, vals, src, st, &mut None)?; + // Each copy's faces are named as the source feature's, with the instance. Its face + // points follow their named faces, as the feature's own did (#2121): a To Object + // extrude's copies reach the face where it is now, not where it was picked. + let moved = with_named_face_points(doc, st, src).map(|(g, _)| g); + let tools = feature_tools_with_constructor(doc, vals, moved.as_ref().unwrap_or(src), st, &mut None)?; for (k, m) in mats.iter().enumerate() { let start = copies.len(); for t in &tools { diff --git a/crates/engine/src/cmd/patterns_tests.rs b/crates/engine/src/cmd/patterns_tests.rs index a8c24c4e6..f55164368 100644 --- a/crates/engine/src/cmd/patterns_tests.rs +++ b/crates/engine/src/cmd/patterns_tests.rs @@ -804,6 +804,31 @@ fn patterns_and_mirrors_of_patterns_and_mirrors() { } } +/// A gear's tooth extruded To Object up to the disc's top, patterned 6 times: after the disc is +/// made twice as thick, every copy reaches the new top like the tooth itself, so the whole part +/// doubles (#2121). The copies kept the 5 mm height of the face where it was picked. +#[test] +fn copies_of_a_to_object_extrude_follow_the_moved_face() { + let mut s = Session::default(); + for (id, p) in [ + ("sketch.create", json!({"plane":"XY","name":"Disc"})), + ("sketch.circle.center", json!({"center":[0,0],"radius":20})), + ("sketch.finish", json!({})), + ("solid.extrude", json!({"distance":5})), + ("sketch.create", json!({"plane":"XY","name":"Tooth"})), + ("sketch.rectangle.two_point", json!({"p0":[18,-2],"p1":[24,2]})), + ("sketch.finish", json!({})), + ("solid.extrude", json!({"sketch":"Tooth","profiles":[0],"to":[0,0,5],"operation":"join"})), + ("solid.pattern.circular", json!({"features":["Extrude2"],"axis":"Z","count":6,"angle":"360 deg"})), + ] { + run(&mut s, id, p); + } + let thin = volume(&mut s); + run(&mut s, "timeline.edit", json!({"feature":"Extrude1","set":{"extent.distance":"10 mm"}})); + let thick = volume(&mut s); + assert!(rel(thick, 2.0 * thin) < 1e-6, "5 mm: {thin} mm³, 10 mm: {thick} mm³ (expected {})", 2.0 * thin); +} + /// A disc with an off-centre hole whose top and bottom edges are chamfered. fn disc_with_chamfered_hole() -> Session { let mut s = Session::default();