From d38e3b9015010044866c1aa21ba8d0f52ad048f5 Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Thu, 29 Oct 2026 22:22:54 +0000 Subject: [PATCH] Close all gaps in solid-like dash pattern for odd-length dashes Found while testing crates/doc/src/blend.rs:197-201 (lerp_dash, solid_like) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/doc/src/blend.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/doc/src/blend.rs b/crates/doc/src/blend.rs index 69ad12781..ced9472a7 100644 --- a/crates/doc/src/blend.rs +++ b/crates/doc/src/blend.rs @@ -196,7 +196,11 @@ pub fn lerp_paint(a: &Paint, b: &Paint, t: f32) -> Paint { /// so dashes open out of a solid line; patterns of different lengths repeat to a common one. fn lerp_dash(x: Option<&Dash>, y: Option<&Dash>, t: f64) -> Option { let solid_like = |d: &Dash| Dash { - pattern: d.pattern.chunks(2).flat_map(|c| [c.iter().sum::(), 0.0]).take(d.pattern.len().max(2)).collect(), + // An odd pattern repeats twice per period, so pair up the doubled one to keep every gap closed. + pattern: if d.pattern.len() % 2 == 1 { d.pattern.repeat(2) } else { d.pattern.clone() } + .chunks(2) + .flat_map(|c| [c.iter().sum::(), 0.0]) + .collect(), offset: d.offset, align_corners: d.align_corners, }; @@ -1423,6 +1427,12 @@ mod tests { assert_eq!(p.at(0.5), (1.0, 1.0)); } + #[test] + fn odd_dash_blends_to_solid_with_closed_gaps() { + let d = lerp_dash(Some(&Dash { pattern: vec![2.0, 3.0, 4.0], ..Default::default() }), None, 1.0).unwrap(); + assert!(d.pattern.iter().skip(1).step_by(2).all(|g| *g == 0.0), "{:?}", d.pattern); + } + #[test] fn copied_steps_get_new_members() { let rect = |x: f64| Arc::new(Node::path(NodeId(7), shapes::rectangle(Rect::new(x, 0.0, x + 10.0, 10.0)), Appearance::default()));