SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch offset: an offset circle no longer reports a degree of freedom (#9264) (#9573)
lewis2e510378d96554
diff --git a/crates/engine/src/cmd/sketch_modify_tests.rs b/crates/engine/src/cmd/sketch_modify_tests.rsindex 83f3c18f49..d29cdeda92 100644--- a/crates/engine/src/cmd/sketch_modify_tests.rs+++ b/crates/engine/src/cmd/sketch_modify_tests.rs@@ -2256,6 +2256,24 @@ fn offset_both_sides_of_a_circle_are_concentric() {assert!(s.execute("sketch.offset", &json!({"curves": [c], "distance": 10, "symmetric": true})).is_err());}+#[test]+fn an_offset_circle_takes_its_radius_from_the_source() {+ // #9264: the offset rebuilds a circle's radius from its source after the solve, but the+ // solve still counted that radius as an unknown: a dimensioned circle and its offset+ // reported 1 degree of freedom.+ let mut s = new_sketch();+ let c = ids(&run(&mut s, "sketch.circle.center", json!({"center": "origin", "radius": 25}))["curves"])[0].clone();+ let d = run(&mut s, "sketch.dimension", json!({"entities": [c], "type": "diameter", "value": "d = 50"}));+ assert_eq!(d["sketch"]["dof"], 0, "{d}");+ let o = run(&mut s, "sketch.offset", json!({"curves": [c], "distance": 5, "side": [40, 0]}));+ assert_eq!(o["sketch"]["dof"], 0, "the offset circle's radius follows its source: {o}");+ let out = ids(&o["curves"])[0].clone();+ run(&mut s, "parameters.change", json!({"name": "d", "expression": "60"}));+ let sk = sketch(&s);+ let CurveKind::Circle { r, .. } = sk.curves[sk.curve_index(&out).unwrap()].kind else { panic!("{out} is not a circle") };+ assert!(close(r, 35.0), "30 mm source plus 5 mm: {r}");+}+#[test]fn offset_refuses_the_combinations_that_would_be_guesswork() {let mut s = new_sketch();diff --git a/crates/sketch/src/offset.rs b/crates/sketch/src/offset.rsindex 5378f34724..cace58562c 100644--- a/crates/sketch/src/offset.rs+++ b/crates/sketch/src/offset.rs@@ -67,6 +67,13 @@ impl Sketch {output(&arc.id) && self.curves.iter().enumerate().any(|(k, other)| k != curve && other.kind.uses(centre) && !output(&other.id))}+ /// A circle an offset made (#9264). The offset sets its radius from the source's after the+ /// solve, so the solve holds that radius instead of counting it as a free unknown.+ pub(crate) fn offset_circle_follows_source(&self, curve: usize) -> bool {+ let Some(circle) = self.curves.get(curve) else { return false };+ matches!(circle.kind, CurveKind::Circle { .. }) && self.offsets.iter().any(|o| o.owns_output(&circle.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) = selfdiff --git a/crates/sketch/src/solver.rs b/crates/sketch/src/solver.rsindex 3e3ab93540..97334ffbbe 100644--- a/crates/sketch/src/solver.rs+++ b/crates/sketch/src/solver.rs@@ -183,7 +183,9 @@ fn layout(sk: &Sketch, hold: &Hold) -> Layout {.iter().enumerate().map(|(i, c)| match c.kind {- CurveKind::Circle { .. } | CurveKind::Ellipse { .. } if c.link.is_none() && !c.fixed && !hold.radii.contains(&i) => {+ CurveKind::Circle { .. } | CurveKind::Ellipse { .. }+ if c.link.is_none() && !c.fixed && !hold.radii.contains(&i) && !sk.offset_circle_follows_source(i) =>+ {n += 1;Some(n - 1)}