Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Sketch: conic curves take their own id prefix, not the constraints' k (#6173) (#8407)

Colin Faulkinghama3ee8957f448
diff --git a/crates/engine/src/cmd/sketch_ids_tests.rs b/crates/engine/src/cmd/sketch_ids_tests.rs
index 76605670e3..cb3d61cb50 100644
--- a/crates/engine/src/cmd/sketch_ids_tests.rs
+++ b/crates/engine/src/cmd/sketch_ids_tests.rs
@@ -328,3 +328,28 @@ fn commands_that_add_nothing_report_empty_lists() {
let r = run(&mut s, "sketch.move_point", json!({"point": strs(&c["points"])[1], "to": [12, 6]}));
assert_eq!(r["created"], json!({"points": [], "curves": [], "constraints": [], "dimensions": []}), "{r}");
}
+
+/// Conic curves take the curve prefix `n`, not the constraints' `k` (#6173): however a conic
+/// is created — drawn, a Move/Copy copy, a pattern copy — its id still says it is a curve.
+#[test]
+fn conic_curves_take_the_n_prefix_not_the_constraints_k() {
+ let mut s = new_sketch();
+ let drawn = run(&mut s, "sketch.conic", json!({"start": [80, 490], "end": [100, 490], "apex": [90, 505], "rho": 0.5}));
+ let conic = strs(&drawn["curves"])[0].clone();
+ assert_eq!(conic, "n1", "a drawn conic starts its own counter");
+
+ // A constraint keeps its prefix, and it no longer shares a counter with conics.
+ run(&mut s, "sketch.constraint.fix", json!({"entity": format!("{conic}.start")}));
+ let sk = sketch(&s);
+ assert!(sk.constraints.iter().any(|k| k.id == "k1"), "constraint ids: {:?}", sk.constraints.iter().map(|k| &k.id).collect::<Vec<_>>());
+
+ let copy = run(&mut s, "sketch.move", json!({"entities": [conic], "translate": [40, 0], "copy": true}));
+ assert_eq!(strs(&copy["curves"]), vec!["n2".to_string()], "a Move/Copy copy continues the conic counter");
+
+ let pattern = run(&mut s, "sketch.pattern.rectangular", json!({"entities": [conic], "count": 2, "spacing": 40}));
+ let made: Vec<String> = strs(&pattern["curves"]);
+ assert!(!made.is_empty(), "{pattern}");
+ for id in made {
+ assert!(id.starts_with('n'), "a pattern copy keeps the conic prefix: {id}");
+ }
+}
diff --git a/crates/engine/src/cmd/sketch_modify.rs b/crates/engine/src/cmd/sketch_modify.rs
index 1fa1a8beb8..e3234a7f9d 100644
--- a/crates/engine/src/cmd/sketch_modify.rs
+++ b/crates/engine/src/cmd/sketch_modify.rs
@@ -2300,7 +2300,7 @@ fn copy_through(
(kind, "e")
}
CurveKind::Spline { .. } => (kind, "s"),
- CurveKind::Conic { .. } => (kind, "k"),
+ CurveKind::Conic { .. } => (kind, "n"),
CurveKind::Line { a, b } => (CurveKind::Line { a: m(a), b: m(b) }, "l"),
CurveKind::Circle { c, r } => (CurveKind::Circle { c: m(c), r: r * scale_r }, "c"),
CurveKind::Arc { c, a, b } => {
diff --git a/crates/engine/src/cmd/sketch_ux_tests.rs b/crates/engine/src/cmd/sketch_ux_tests.rs
index 4ec73ac095..341b115e1e 100644
--- a/crates/engine/src/cmd/sketch_ux_tests.rs
+++ b/crates/engine/src/cmd/sketch_ux_tests.rs
@@ -692,16 +692,16 @@ fn dragging_a_conic_reads_rho_off_the_cursor_and_its_apex_slides_like_any_point(
// Grabbed on the curve itself (its midpoint, at the default rho of 0.5): `rho` follows the
// cursor, read off where it falls between the chord's midpoint (20, 0) and the apex (20,
// 20). The three defining points stay exactly where they were.
- drag(&mut s, "k1", [20.0, 10.0], [20.0, 14.0]);
+ drag(&mut s, "n1", [20.0, 10.0], [20.0, 14.0]);
assert!((rho(&s) - 0.7).abs() < 1e-6, "rho after drag: {}", rho(&s));
- assert!(pt(&s, "k1.start").dist(v(0.0, 0.0)) < 1e-9);
- assert!(pt(&s, "k1.end").dist(v(40.0, 0.0)) < 1e-9);
- assert!(pt(&s, "k1.apex").dist(v(20.0, 20.0)) < 1e-9);
+ assert!(pt(&s, "n1.start").dist(v(0.0, 0.0)) < 1e-9);
+ assert!(pt(&s, "n1.end").dist(v(40.0, 0.0)) < 1e-9);
+ assert!(pt(&s, "n1.apex").dist(v(20.0, 20.0)) < 1e-9);
// Grabbed on the apex itself: it slides like any other point (not a `rho` edit), and `rho`
// is unaffected.
- drag(&mut s, "k1.apex", [20.0, 20.0], [10.0, 30.0]);
- assert!(pt(&s, "k1.apex").dist(v(10.0, 30.0)) < 1e-9);
+ drag(&mut s, "n1.apex", [20.0, 20.0], [10.0, 30.0]);
+ assert!(pt(&s, "n1.apex").dist(v(10.0, 30.0)) < 1e-9);
assert!((rho(&s) - 0.7).abs() < 1e-6, "rho after apex drag: {}", rho(&s));
}
diff --git a/crates/sketch/src/link.rs b/crates/sketch/src/link.rs
index ca5a576261..7e56b7f5d9 100644
--- a/crates/sketch/src/link.rs
+++ b/crates/sketch/src/link.rs
@@ -714,7 +714,7 @@ impl Sketch {
LCurve::Line(a, b) => (CurveKind::Line { a: point(self, a)?, b: point(self, b)? }, "l"),
LCurve::Circle(c, r) => (CurveKind::Circle { c: point(self, c)?, r }, "c"),
LCurve::Arc(c, a, b) => (CurveKind::Arc { c: point(self, c)?, a: point(self, a)?, b: point(self, b)? }, "a"),
- LCurve::Conic(a, b, x, rho) => (CurveKind::Conic { a: point(self, a)?, b: point(self, b)?, apex: point(self, x)?, rho }, "k"),
+ LCurve::Conic(a, b, x, rho) => (CurveKind::Conic { a: point(self, a)?, b: point(self, b)?, apex: point(self, x)?, rho }, "n"),
LCurve::Ellipse(c, m, r) => (CurveKind::Ellipse { c: point(self, c)?, m: point(self, m)?, r }, "e"),
LCurve::Spline(a, b, f, n, control, degree, periodic) => {
let mut pts = vec![point(self, a)?];
diff --git a/crates/sketch/src/link_identity_tests.rs b/crates/sketch/src/link_identity_tests.rs
index 543470a642..9240bbaf91 100644
--- a/crates/sketch/src/link_identity_tests.rs
+++ b/crates/sketch/src/link_identity_tests.rs
@@ -360,3 +360,17 @@ fn edge_on_face_lays_out_as_one_silhouette_line_and_stays_current() {
assert_eq!(sk.link_curves(&link).len(), 4);
assert!(!sk.link(&link).unwrap().lost);
}
+
+/// A conic that comes with a link (projected geometry) takes the curve prefix `n` like a drawn
+/// one, not the constraints' `k` (#6173).
+#[test]
+fn linked_conic_curves_take_the_n_prefix_not_the_constraints_k() {
+ let mut sk = Sketch::new();
+ let geom = vec![
+ LinkGeom::Line(Vec2::new(0.0, 0.0), Vec2::new(10.0, 0.0)),
+ LinkGeom::Conic { a: Vec2::new(10.0, 0.0), apex: Vec2::new(15.0, 4.0), b: Vec2::new(20.0, 0.0), rho: 0.5 },
+ ];
+ let link = sk.add_link(LinkKind::Project, LinkSource::Origin, &geom).unwrap();
+ let ids: Vec<String> = sk.link_curves(&link).iter().map(|c| sk.curves[*c].id.clone()).collect();
+ assert_eq!(ids, vec!["l1".to_string(), "n1".to_string()], "linked curve ids");
+}
diff --git a/crates/sketch/src/model.rs b/crates/sketch/src/model.rs
index d426826c45..492789c4ca 100644
--- a/crates/sketch/src/model.rs
+++ b/crates/sketch/src/model.rs
@@ -1582,7 +1582,7 @@ impl Sketch {
if !(rho.is_finite() && *rho > 1e-6 && *rho < 1.0 - 1e-6) {
return Err(SketchError::Invalid("rho must be between 0 and 1".into()));
}
- "k"
+ "n"
}
};
let id = self.curve_id(id, prefix)?;
diff --git a/crates/sketch/src/pattern.rs b/crates/sketch/src/pattern.rs
index 5ac99d5784..7f98347e48 100644
--- a/crates/sketch/src/pattern.rs
+++ b/crates/sketch/src/pattern.rs
@@ -531,7 +531,7 @@ fn copy_through(sk: &mut Sketch, cs: &[usize], ps: &[usize], f: &dyn Fn(Vec2) ->
let prefix = match &kind {
CurveKind::Ellipse { .. } => "e",
CurveKind::Spline { .. } => "s",
- CurveKind::Conic { .. } => "k",
+ CurveKind::Conic { .. } => "n",
CurveKind::Line { .. } => "l",
CurveKind::Circle { .. } => "c",
CurveKind::Arc { .. } => "a",