Cap Liquify dabs while expanding a segment, not only before it (#1708)

This commit is contained in:
MarekSpodBiedry 2026-10-13 18:15:35 +02:00
parent 0d0ea352df
commit ce53bb7c57
1 changed files with 17 additions and 1 deletions

View File

@ -324,7 +324,7 @@ impl Dabber {
self.dabs.push(self.dab(b, pb));
return;
};
if self.dabs.len() > MAX_DABS {
if self.dabs.len() >= MAX_DABS {
return;
}
let len = a.distance(b);
@ -337,6 +337,9 @@ impl Dabber {
}
let mut s = self.spacing - self.carry;
while s <= len {
if self.dabs.len() >= MAX_DABS {
return;
}
let t = s / len;
self.dabs.push(self.dab(a.lerp(b, t), pa + (pb - pa) * t));
s += self.spacing;
@ -835,6 +838,19 @@ mod tests {
assert_eq!(dabs(&[Point::new(5.0, 5.0)], 10.0), vec![Point::new(5.0, 5.0)]);
}
#[test]
fn one_long_segment_stays_within_the_dab_cap() {
let mut h = Dabber::with(1.0, Some(1.0), true);
for _ in 0..MAX_DABS + 100 {
h.push((Point::new(3.0, 3.0), 1.0));
}
assert_eq!(h.dabs.len(), MAX_DABS);
let d = dabs(&[Point::new(0.0, 0.0), Point::new(1.0e9, 0.0)], 1.0);
assert!(d.len() <= MAX_DABS + 1, "{} dabs", d.len());
let d = dabs(&[Point::new(0.0, 0.0), Point::new(f64::MAX, f64::MAX)], 1.0);
assert!(d.len() <= MAX_DABS + 1, "{} dabs", d.len());
}
#[test]
fn warp_is_deterministic_and_localized() {
let pts = [Point::new(200.0, 100.0), Point::new(240.0, 100.0)];