mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-31 13:17:19 -06:00
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 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Haiku 5.5
parent
60833ae800
commit
d38e3b9015
+11
-1
@@ -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<Dash> {
|
||||
let solid_like = |d: &Dash| Dash {
|
||||
pattern: d.pattern.chunks(2).flat_map(|c| [c.iter().sum::<f64>(), 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::<f64>(), 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()));
|
||||
|
||||
Reference in New Issue
Block a user