From 6dc6372b13762cfacdba05b1eb223fbd0ba089a3 Mon Sep 17 00:00:00 2001 From: tbreckle <25928171+tbreckle@users.noreply.github.com> Date: Sun, 11 Oct 2026 20:19:32 +0200 Subject: [PATCH] fix(sketch): a centerline can be switched straight to construction sketch.construction set `construction` but left `centerline` on, so the curve stayed a centerline (drawn dash-dot, still marked as an axis) until it was first switched back to normal. Making a curve construction now clears its centerline flag, mirroring sketch.centerline. --- crates/engine/src/cmd/sketch.rs | 8 ++++++-- crates/engine/src/cmd/sketch_ux_tests.rs | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/sketch.rs b/crates/engine/src/cmd/sketch.rs index e6cffb36..bcfb7955 100644 --- a/crates/engine/src/cmd/sketch.rs +++ b/crates/engine/src/cmd/sketch.rs @@ -1703,14 +1703,18 @@ fn construction(s: &mut Session, p: &Value) -> Result { let cs: Vec = ids.iter().map(|id| sk.curve_index(id).ok_or_else(|| bad(cmd, format!("unknown curve `{id}`")))).collect::>()?; // The selection switches together (a slot or polygon as a whole): to construction - // unless all of it already is. Projected curves may switch too. + // unless all of it already is. Projected curves may switch too. A centerline that + // becomes construction stops being a centerline (one line type at a time). let to = want.unwrap_or_else(|| !cs.iter().all(|c| sk.curves.get(*c).is_some_and(|c| c.construction))); let mut n = 0; for c in cs { if let Some(cu) = sk.curves.get_mut(c) - && cu.construction != to + && (cu.construction != to || to && cu.centerline) { cu.construction = to; + if to { + cu.centerline = false; + } n += 1; } } diff --git a/crates/engine/src/cmd/sketch_ux_tests.rs b/crates/engine/src/cmd/sketch_ux_tests.rs index 7d6e0080..56dcdb8b 100644 --- a/crates/engine/src/cmd/sketch_ux_tests.rs +++ b/crates/engine/src/cmd/sketch_ux_tests.rs @@ -237,6 +237,21 @@ fn construction_toggle_takes_shapes_out_of_profiles_and_back() { assert!(s.execute("sketch.construction", &json!({"curves": ["nope"]})).is_err()); } +#[test] +fn centerline_can_become_construction_directly() { + let mut s = new_sketch(); + let l = curve_ids(&run(&mut s, "sketch.line", json!({"points": [[0, 0], [20, 0]]}))); + run(&mut s, "sketch.centerline", json!({ "curves": l, "value": true })); + let r = run(&mut s, "sketch.construction", json!({ "curves": l, "value": true })); + assert_eq!(r["changed"], 1); + let sk = sketch(&s); + assert!(sk.curves.iter().filter(|c| l.contains(&c.id)).all(|c| c.construction && !c.centerline)); + // And back to a centerline. + run(&mut s, "sketch.centerline", json!({ "curves": l, "value": true })); + let sk = sketch(&s); + assert!(sk.curves.iter().filter(|c| l.contains(&c.id)).all(|c| c.centerline && !c.construction)); +} + #[test] fn projected_geometry_can_become_construction() { let mut s = Session::default();