From fac811565b8b50e5199f29be23b146a75dd1cb8a Mon Sep 17 00:00:00 2001 From: phanoob Date: Tue, 27 Oct 2026 12:38:15 +0000 Subject: [PATCH] Sketch: an arc centred on an existing point shows its Coincident glyph (Refs #7299) (#7346) * Claim: centre arc on an existing point shows its Coincident glyph (Refs #7299) Co-Authored-By: Claude Opus 5.5 * Sketch: an arc centred on an existing point shows its Coincident glyph (Refs #7299) The Centre arc tool sent a centre snapped to an existing point as that point's id, so the arc shared it with no constraint and the sketch drew no glyph. A plain point snap now goes as its place, where draw's connect ties the new centre with a Coincident; midpoint, on-curve, crossing and body-vertex snaps still go as refs. 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 | 17 +++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/sketch_corner_ui_tests.rs b/crates/ui-egui/src/sketch_corner_ui_tests.rs index aa14d0629..1cdead5c1 100644 --- a/crates/ui-egui/src/sketch_corner_ui_tests.rs +++ b/crates/ui-egui/src/sketch_corner_ui_tests.rs @@ -712,6 +712,41 @@ fn centre_circle_clicked_through_a_line_end_stays_on_it() { ); } +/// #7299: the centre arc tool, its centre snapped to a rectangle's corner, ties the arc to the +/// corner with a Coincident (which the sketch shows as a glyph), not by quietly sharing the corner +/// as its centre. +#[test] +fn centre_arc_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.arc.center_point"})).unwrap(); + for at in [[40, 30, 0], [34, 30, 0], [40, 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::Arc { c, .. } => Some(c), + _ => None, + }); + let centre = centre.unwrap_or_else(|| panic!("an arc is drawn: {:?}", h.app.status)); + assert_ne!(centre, corner, "the arc 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); +} + /// #4691: the Point tool clicked on a line's midpoint makes a point held there (a MidPoint /// constraint), not a free point that happens to sit on the middle. #[test] diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rs index 4e2af4da2..2e1bfcd19 100644 --- a/crates/ui-egui/src/tools.rs +++ b/crates/ui-egui/src/tools.rs @@ -534,10 +534,19 @@ fn run_shape(app: &mut SolveApp, t: &Tool) -> Result, String> { "sketch.circle.two_point" => json!({"p0": xy(&p[0]), "p1": xy(&p[1])}), "sketch.circle.three_point" => json!({"p0": xy(&p[0]), "p1": xy(&p[1]), "p2": xy(&p[2])}), "sketch.arc.three_point" => json!({"start": arg(&p[0]), "end": arg(&p[1]), "through": arg(&p[2])}), - "sketch.arc.center_point" => match crate::sketch_dims::locked_value(app, t, "Sweep") { - Some(sweep) => json!({"center": arg(&p[0]), "start": arg(&p[1]), "sweep": sweep.to_degrees()}), - None => json!({"center": arg(&p[0]), "start": arg(&p[1]), "end": xy(&p[2])}), - }, + "sketch.arc.center_point" => { + // 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. + 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]), + }; + match crate::sketch_dims::locked_value(app, t, "Sweep") { + Some(sweep) => json!({"center": center, "start": arg(&p[1]), "sweep": sweep.to_degrees()}), + None => json!({"center": center, "start": arg(&p[1]), "end": xy(&p[2])}), + } + } "sketch.polygon.inscribed" | "sketch.polygon.circumscribed" => { let a = (p[1].0 - p[0].0).angle().to_degrees(); json!({"center": xy(&p[0]), "radius": d(0, 1), "sides": sides, "angle": a})