mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-14 19:26:56 -04:00
Merge pull request #1779 from MarekSpodBiedry/issue-1708
Cap Liquify dabs while expanding a segment, not only before it (#1708)
This commit is contained in:
1 file changed
+17
-1
@@ -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)];
|
||||
|
||||
Reference in new issue
Block a user