From 56622e4be88c63d420f3fd94b869a8f923890868 Mon Sep 17 00:00:00 2001 From: DuBearte <130190089+DuBearte@users.noreply.github.com> Date: Thu, 15 Oct 2026 08:22:42 -0400 Subject: [PATCH] Sketch: preview the whole midpoint line while drawing it (#1371) The Midpoint Line tool previews the line from the cursor's mirror image through the middle to the cursor, which is what the second click commits. Fixes #1358. --- crates/ui-egui/src/sketch_display_preview_tests.rs | 2 ++ crates/ui-egui/src/tools.rs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/crates/ui-egui/src/sketch_display_preview_tests.rs b/crates/ui-egui/src/sketch_display_preview_tests.rs index adc9f32b..c7fc01e0 100644 --- a/crates/ui-egui/src/sketch_display_preview_tests.rs +++ b/crates/ui-egui/src/sketch_display_preview_tests.rs @@ -41,6 +41,8 @@ fn pixel_preview_temporary_curves_match_committed_geometry_and_sampling() { let cases: Vec<(&str, Vec<[f64; 2]>, [f64; 2], Option, Option, Value)> = vec![ ("sketch.circle.center", vec![[0., 0.]], [1., 0.], None, None, json!({"center":[0,0],"radius":1})), ("sketch.circle.two_point", vec![[-1., 0.]], [1., 0.], None, None, json!({"p0":[-1,0],"p1":[1,0]})), + // #1358: the whole line, both sides of the middle. + ("sketch.line.midpoint", vec![[0., 0.]], [1., 0.5], None, None, json!({"mid":[0,0],"end":[1,0.5]})), ("sketch.circle.three_point", vec![[1., 0.], [-1., 0.]], [0., 1.], None, None, json!({"p0":[1,0],"p1":[-1,0],"p2":[0,1]})), ("sketch.arc.three_point", vec![[1., 0.], [-1., 0.]], [0., -1.], None, None, json!({"start":[1,0],"end":[-1,0],"through":[0,-1]})), ( diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rs index 1f643373..8a8e22ae 100644 --- a/crates/ui-egui/src/tools.rs +++ b/crates/ui-egui/src/tools.rs @@ -586,6 +586,14 @@ pub(crate) fn preview_curve(t: &Tool, hover: Vec2, sweep: Option, rho: Opti ("sketch.circle.two_point", [a]) => { sk.add_circle((*a + hover) * 0.5, a.dist(hover) * 0.5, None, None).ok()?; } + // The first click is the middle: the line runs from the cursor's mirror image through + // it to the cursor (#1358), not from the middle to the cursor. + ("sketch.line.midpoint", [m]) => { + if m.dist(hover) <= 1e-9 { + return None; + } + sk.add_line(*m * 2.0 - hover, hover, None, None, None).ok()?; + } ("sketch.circle.three_point" | "sketch.arc.three_point", [a, b]) => { let ab = *b - *a; let ah = hover - *a;