From 578b26cc7c6dd7ad55659f834f67be7a09d6284c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 16:50:35 -0800 Subject: [PATCH] Tool overlays: draw every dash of a dashed piece as line segments dashes_from drew the cut first dash and a line shorter than the rest of a dash as one path. The tessellator snaps horizontal and vertical line segments to pixels but not paths, so those dashes could look softer than the rest. Each line of them is now its own line segment, as Shape::dashed_line draws a dash, and a line of no length is skipped. --- crates/ui-egui/src/canvas/overlays.rs | 10 ++++++++-- crates/ui-egui/src/canvas/tests.rs | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/canvas/overlays.rs b/crates/ui-egui/src/canvas/overlays.rs index e3612bc880..613b0fae9c 100644 --- a/crates/ui-egui/src/canvas/overlays.rs +++ b/crates/ui-egui/src/canvas/overlays.rs @@ -428,7 +428,7 @@ pub(super) fn dashes_from(line: &[Pos2], s: Stroke, from: f64, out: &mut Vec) { + out.extend(line.windows(2).filter(|w| w[0] != w[1]).map(|w| Shape::line_segment([w[0], w[1]], s))); } impl SharedPaths { diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 8830edf1c7..5d5a5aa3d8 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -201,6 +201,14 @@ fn a_line_dashed_in_pieces_dashes_as_the_whole_line_does() { let (want, got) = (covered(&one_go), covered(&pieces)); assert_eq!(want.len(), got.len(), "{want:?} {got:?}"); assert!(want.iter().zip(&got).all(|(w, g)| (w.0 - g.0).abs() < 1e-3 && (w.1 - g.1).abs() < 1e-3), "{want:?} {got:?}"); + // Every dash is drawn as line segments with a length, as `Shape::dashed_line` draws them: the + // cut first dash, a dash cut on a vertex (at 4) and a line shorter than the rest of a dash too. + let mut ends = vec![]; + overlays::dashes_from(&along(&[0.0, 4.0, 10.0]), s, 0.0, &mut ends); + overlays::dashes_from(&along(&[0.0, 1.0, 2.0]), s, 1.0, &mut ends); + for shape in one_go.iter().chain(&pieces).chain(&ends) { + assert!(matches!(shape, Shape::LineSegment { points: [a, b], .. } if a != b), "{shape:?}"); + } } #[test]