diff --git a/crates/engine/src/cmd/sketch_ux_tests.rs b/crates/engine/src/cmd/sketch_ux_tests.rs index 5bce988cf..8b2ca858e 100644 --- a/crates/engine/src/cmd/sketch_ux_tests.rs +++ b/crates/engine/src/cmd/sketch_ux_tests.rs @@ -1525,6 +1525,34 @@ fn the_first_dimension_does_not_scale_a_sketch_that_has_a_size() { assert!(out.get("scaled").is_none(), "{out}"); } +/// #3786: shapes that nothing links together are not one drawing: the first dimension sizes +/// the shape it measures and leaves the other alone. +#[test] +fn the_first_dimension_leaves_a_separate_shape_alone() { + let mut s = new_sketch(); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [20, 10]})); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [30, 10], "p1": [45, 20]})); + let other = sketch(&s); + let out = run(&mut s, "sketch.dimension", json!({"entities": ["l1"], "value": "30 mm", "scale_sketch": true})); + assert!(out.get("scaled").is_none(), "{out}"); + let after = sketch(&s); + // The second rectangle (points 4..8, after the origin and the first rectangle's four) is untouched. + for (p, q) in other.points.iter().zip(&after.points).skip(5) { + assert!(q.pos.dist(p.pos) < 1e-6, "{} {:?} -> {:?}", p.id, p.pos, q.pos); + } +} + +/// #1365 still holds for one drawing: shapes joined by a constraint scale together. +#[test] +fn the_first_dimension_scales_shapes_joined_by_a_constraint() { + let mut s = new_sketch(); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [20, 10]})); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [30, 10], "p1": [45, 20]})); + run(&mut s, "sketch.constraint.coincident", json!({"a": "l1.start", "b": "l5.start"})); + let out = run(&mut s, "sketch.dimension", json!({"entities": ["l1"], "value": "40 mm", "scale_sketch": true})); + assert!(out.get("scaled").is_some(), "{out}"); +} + /// The cursor fallback shares the held solves' frame budget; a scripted drag can finish later. #[test] fn cursor_fallback_respects_an_exhausted_live_frame_budget() { diff --git a/crates/sketch/src/model.rs b/crates/sketch/src/model.rs index 605937df5..e9bac7b80 100644 --- a/crates/sketch/src/model.rs +++ b/crates/sketch/src/model.rs @@ -1029,7 +1029,8 @@ impl Sketch { /// with nothing that fixes a size: no other driving length dimension, nothing fixed, /// projected or patterned, no offsets and no 3D curves. Every geometric constraint /// (coincident, horizontal, parallel, tangent, equal, symmetric, …) and every angle holds - /// on the scaled sketch as it held before. `None` when the sketch does not qualify. + /// on the scaled sketch as it held before. `None` when the sketch does not qualify, also + /// when its curves form several separate chains (#3786): the dimension sizes only its own. pub fn scaled_for_first_dimension(&self, factor: f64) -> Option { if !(factor.is_finite() && (1e-6..=1e6).contains(&factor)) { return None; @@ -1049,6 +1050,31 @@ impl Sketch { { return None; } + // Shapes nothing joins (#3786) are not one drawing: only one connected chain of curves + // scales. Curves and driving constraints join their points; the origin is a point too. + let mut parent: Vec = (0..self.points.len()).collect(); + for c in &self.curves { + let ids = c.kind.point_ids(); + for w in ids.windows(2) { + if let [a, b] = *w { + union(&mut parent, a, b); + } + } + } + for c in self.constraints.iter().filter(|c| !c.driven) { + let ids = self.constraint_points(&c.kind); + for w in ids.windows(2) { + if let [a, b] = *w { + union(&mut parent, a, b); + } + } + } + let mut roots = self.curves.iter().filter_map(|c| c.kind.point_ids().first().map(|&p| find(&mut parent, p))); + if let Some(first) = roots.next() + && roots.any(|r| r != first) + { + return None; + } let mut out = self.clone(); for p in out.points.iter_mut().filter(|p| !p.fixed) { p.pos = p.pos * factor;