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]