From 75c8700724dbd2189014049f5eb1df99e1c8af5e Mon Sep 17 00:00:00 2001 From: phanoob Date: Tue, 27 Oct 2026 12:38:23 +0000 Subject: [PATCH] Sketch: a circle centred on an existing point shows its Coincident glyph (#7299) (#7331) * claim: #7299 Co-Authored-By: Claude Opus 5.5 * Sketch: a circle centred on an existing point shows its Coincident glyph (#7299) The centre circle tool sent a centre snapped to an existing point as that point's id, so the circle shared it: attached, but with no constraint and so no glyph to see, pick or delete. A plain point snap now goes as its place, where `connect` ties the new centre to the point with a Coincident the sketch draws. Midpoint, on-curve, crossing and body-vertex snaps still go as refs, so the centre stays held there (#3099 keeps passing). Fixes #7299 Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Phanoob Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/sketch_corner_ui_tests.rs | 35 ++++++++++++++++++++ crates/ui-egui/src/tools.rs | 11 ++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/sketch_corner_ui_tests.rs b/crates/ui-egui/src/sketch_corner_ui_tests.rs index 1cdead5c1..1a17b4f95 100644 --- a/crates/ui-egui/src/sketch_corner_ui_tests.rs +++ b/crates/ui-egui/src/sketch_corner_ui_tests.rs @@ -763,3 +763,38 @@ fn a_point_clicked_on_a_line_midpoint_is_held_there() { let held = sk.constraints.iter().any(|c| matches!(c.kind, solidcraft_engine::sketch::ConstraintKind::Midpoint { .. })); assert!(held, "no MidPoint constraint: {:?}", sk.constraints.iter().map(|c| &c.kind).collect::>()); } + +/// #7299: the centre circle tool, its centre snapped to a rectangle's corner, ties the circle +/// to the corner with a Coincident (which the sketch shows as a glyph that can be picked and +/// deleted), not by quietly sharing the corner as its centre. +#[test] +fn centre_circle_on_an_existing_point_is_tied_by_a_coincident() { + use solidcraft_engine::sketch::ConstraintKind; + let mut h = crate::scenario::Harness::new(); + h.app.run("sketch.create", json!({"plane":"XY"})).unwrap(); + h.app.run("sketch.rectangle.two_point", json!({"p0":[10,10],"p1":[40,30]})).unwrap(); + h.step(&json!({"call":"ui.view","params":{"view":"fit"}})).unwrap(); + h.settle(); + let sid = h.app.session.active_sketch.unwrap(); + let sk = h.app.session.model.state().sketch(sid).unwrap().sketch.clone(); + let at_corner = |p: Option<_>| p.is_some_and(|p: Vec2| (p.x - 40.0).abs() < 1e-9 && (p.y - 30.0).abs() < 1e-9); + let corner = (0..sk.points.len()).find(|&i| at_corner(sk.point(i))).unwrap(); + h.step(&json!({"start":"sketch.circle.center"})).unwrap(); + for at in [[40, 30, 0], [34, 24, 0]] { + h.step(&json!({"move":{"world":at}})).unwrap(); + h.step(&json!({"click":{"world":at}})).unwrap(); + } + let sk = h.app.session.model.state().sketch(sid).unwrap().sketch.clone(); + let centre = sk.curves.iter().find_map(|c| match c.kind { + CurveKind::Circle { c, .. } => Some(c), + _ => None, + }); + let centre = centre.unwrap_or_else(|| panic!("a circle is drawn: {:?}", h.app.status)); + assert_ne!(centre, corner, "the circle has a centre of its own"); + assert!(at_corner(sk.point(centre)), "the centre is on the corner"); + let tied = sk + .constraints + .iter() + .any(|k| matches!(k.kind, ConstraintKind::Coincident { p, q } if (p, q) == (corner, centre) || (p, q) == (centre, corner))); + assert!(tied, "a Coincident ties the centre to the corner: {:?}", sk.constraints); +} diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rs index 2e1bfcd19..33d67dea0 100644 --- a/crates/ui-egui/src/tools.rs +++ b/crates/ui-egui/src/tools.rs @@ -524,8 +524,15 @@ fn run_shape(app: &mut SolveApp, t: &Tool) -> Result, String> { } "sketch.rectangle.three_point" => json!({"p0": xy(&p[0]), "p1": xy(&p[1]), "p2": xy(&p[2])}), "sketch.circle.center" => { - // A second click snapped to a point keeps the circle on that point (#3099). - let mut v = json!({"center": arg(&p[0]), "radius": d(0, 1)}); + // A centre snapped to an existing point goes as its place, where `connect` ties + // them with a Coincident the sketch shows (#7299); a midpoint, on-curve, crossing or + // body-vertex snap goes as itself, so the centre is held there. A second click + // snapped to a point keeps the circle on that point (#3099). + let center = match &p[0].1 { + Some(id) if ["mid:", "on:", "vertex:", "x:"].iter().any(|k| id.starts_with(k)) => json!(id), + _ => xy(&p[0]), + }; + let mut v = json!({"center": center, "radius": d(0, 1)}); if p[1].1.is_some() { v["through"] = arg(&p[1]); }