From e2c9f908f89db63b1ae9719e438a634285eb86ef Mon Sep 17 00:00:00 2001 From: semmelrinde <124386289+semmelrinde@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:12:15 +0000 Subject: [PATCH] Sketch: an offset slot can still be moved by the dimension that places it (#6569) (#6697) * claim: #6569 * Sketch: an offset slot can still be moved by the dimension that places it (#6569) An offset arc is drawn round its source's own centre, and its ends are held while the sketch solves (the offset is rebuilt from its source afterwards). Its arc condition, both ends as far from the centre, then only tied that shared centre, and the source arc with it, to the middle of the held ends: a slot offset by 1 mm lost a degree of freedom, and the length that places it was refused as conflicting. The solver and the constructive reading now leave out the arc condition of an offset arc round its source's centre (Sketch::offset_arc_follows_source), as #4466 did for the Parallel between an offset line and its source. The source's own arc keeps the centre; nothing changes without an offset. Co-Authored-By: Claude Opus 5.5 * Sketch: a test for a rounded rectangle with an offset round it (#6569) kaievns's case from the review: the offset's corner arcs tied each corner centre to a 45 degree line, so the height followed the width and every width change was refused. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/engine/src/cmd/sketch_modify_tests.rs | 41 ++++++++++++++++++++ crates/sketch/src/loci.rs | 4 ++ crates/sketch/src/offset.rs | 15 +++++++ crates/sketch/src/solver.rs | 6 ++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/sketch_modify_tests.rs b/crates/engine/src/cmd/sketch_modify_tests.rs index a2be9291b..aa5be825c 100644 --- a/crates/engine/src/cmd/sketch_modify_tests.rs +++ b/crates/engine/src/cmd/sketch_modify_tests.rs @@ -2056,6 +2056,47 @@ fn an_offset_leaves_its_source_lines_free_to_turn() { assert_eq!(o["sketch"]["dof"], corners["sketch"]["dof"], "{o}"); } +#[test] +fn an_offset_slot_still_moves_with_the_dimension_that_places_it() { + // #6569: an offset arc shares its source's centre and its ends are held while the sketch + // solves. Its own arc condition tied that centre to the middle of the held ends: the slot + // lost a degree of freedom, and the length that places it was refused as conflicting. + let build = |offset: bool| { + let mut s = new_sketch(); + run(&mut s, "sketch.line", json!({"points": [[0, 20], [0, 10]], "construction": true})); + run(&mut s, "sketch.constraint.fix", json!({"entity": "l1.start"})); + run(&mut s, "sketch.constraint.horizontal_vertical", json!({"line": "l1", "mode": "vertical"})); + run(&mut s, "sketch.dimension", json!({"entities": ["l1"], "value": "a = 10"})); + let slot = run(&mut s, "sketch.slot.center_to_center", json!({"p0": [0, 10], "p1": [8, 10], "width": 3})); + let dof = if offset { + run(&mut s, "sketch.offset", json!({"curves": ["l2"], "distance": 1, "side": [4, 5]}))["sketch"]["dof"].clone() + } else { + slot["sketch"]["dof"].clone() + }; + (s, dof) + }; + let (mut plain, without) = build(false); + let (mut s, with) = build(true); + assert_eq!(with, without, "the offset takes no freedom away from the slot"); + for s in [&mut plain, &mut s] { + run(s, "parameters.change", json!({"name": "a", "expression": "8"})); + } + // The slot moves as it does without the offset, and the offset follows it, 1 mm out. + let (a, b) = (sketch(&plain), sketch(&s)); + for p in &a.points { + let q = b.points.iter().find(|q| q.id == p.id).unwrap(); + assert!(p.pos.dist(q.pos) < 1e-9, "{} at {:?}, without the offset at {:?}", p.id, q.pos, p.pos); + } + let arc = |id: &str| match b.curves[b.curve_index(id).unwrap()].kind { + CurveKind::Arc { c, a, .. } => (c, b.points[a].pos.dist(b.points[c].pos)), + ref other => panic!("{id} is {other:?}"), + }; + for (source, output) in [("a1", "a3"), ("a2", "a4")] { + let ((c, r), (oc, or)) = (arc(source), arc(output)); + assert!(c == oc && close(or - r, 1.0), "{output} is round {source}'s centre, 1 mm out: {r} and {or}"); + } +} + #[test] fn offset_driver_covers_disconnected_selections_and_refuses_bad_values_atomically() { let mut s = new_sketch(); diff --git a/crates/sketch/src/loci.rs b/crates/sketch/src/loci.rs index 2dbe5d758..b8215ecb3 100644 --- a/crates/sketch/src/loci.rs +++ b/crates/sketch/src/loci.rs @@ -988,6 +988,10 @@ pub(crate) fn read(sk: &Sketch, before: &dyn Fn(usize) -> Option, on_curve } for (k, rd) in rounds.iter().enumerate() { let Some(Round { c, ends: Some((a, b)) }) = *rd else { continue }; + // An offset's arc follows its source's centre; its held ends don't place it (#6569). + if sk.offset_arc_follows_source(k) { + continue; + } match r_of(k) { Some(r) => { rel(c, a, Rel::Dist(r)); diff --git a/crates/sketch/src/offset.rs b/crates/sketch/src/offset.rs index 0e2fabc23..23b013dab 100644 --- a/crates/sketch/src/offset.rs +++ b/crates/sketch/src/offset.rs @@ -52,6 +52,21 @@ impl Sketch { }) } + /// An arc an offset made round its source's own centre (#6569). Its ends are held while the + /// sketch solves, so its own condition, both ends as far from the centre, only tied that + /// centre (and the source with it) to the middle of the held ends: a slot offset by 1 mm + /// could no longer be moved by the dimension that places it. The source's own arc keeps the + /// centre, and the offset is rebuilt from the source after the solve. + pub(crate) fn offset_arc_follows_source(&self, curve: usize) -> bool { + if self.offsets.is_empty() { + return false; + } + let Some(arc) = self.curves.get(curve) else { return false }; + let CurveKind::Arc { c: centre, .. } = arc.kind else { return false }; + let output = |id: &str| self.offsets.iter().any(|o| o.owns_output(id)); + output(&arc.id) && self.curves.iter().enumerate().any(|(k, other)| k != curve && other.kind.uses(centre) && !output(&other.id)) + } + /// Endpoints of a normal-distance annotation, evaluated from its source curve. pub fn offset_dimension_points(&self, output: &str) -> Option<(Vec2, Vec2)> { let (source, forward, distance) = self diff --git a/crates/sketch/src/solver.rs b/crates/sketch/src/solver.rs index 2c4d371e8..6521bbb38 100644 --- a/crates/sketch/src/solver.rs +++ b/crates/sketch/src/solver.rs @@ -1817,14 +1817,16 @@ fn initial_x(sk: &Sketch, lay: &Layout) -> Vec { /// point. fn build_blocks<'a>(sk: &'a Sketch, lay: &Layout, on_curve: &[(usize, usize)]) -> (Vec<(Block<'a>, Vec)>, Vec) { let mut raw = Vec::new(); - for c in &sk.curves { + for (k, c) in sk.curves.iter().enumerate() { if let CurveKind::Spline { pts, periodic: true, .. } = &c.kind && let (Some(a), Some(b)) = (pts.first(), pts.last()) && a != b { raw.push(Block::Closure { a: *a, b: *b }); } - if let CurveKind::Arc { c, a, b } = c.kind { + if let CurveKind::Arc { c, a, b } = c.kind + && !sk.offset_arc_follows_source(k) + { raw.push(Block::Arc { c, a, b }); } }