diff --git a/crates/vector/src/flatten.rs b/crates/vector/src/flatten.rs index 9ff8a2aaba..155d7ae327 100644 --- a/crates/vector/src/flatten.rs +++ b/crates/vector/src/flatten.rs @@ -74,7 +74,15 @@ impl Polyline { let (a, b, len) = pieces[i]; let t = ((s - start) / len).clamp(0.0, 1.0); let dir = ((b.0 - a.0) / len, (b.1 - a.1) / len); - ((a.0 + (b.0 - a.0) * t, a.1 + (b.1 - a.1) * t), dir) + // The ends exactly: far from the origin the blend loses the near end's digits. + let point = if t <= 0.0 { + a + } else if t >= 1.0 { + b + } else { + (a.0 + (b.0 - a.0) * t, a.1 + (b.1 - a.1) * t) + }; + (point, dir) }) .collect() } @@ -358,6 +366,11 @@ mod tests { // Closed, the closing piece counts. let closed = Polyline { closed: true, ..line }; assert_eq!(closed.length(), 20.0 + 200f64.sqrt()); + // A piece from far away ends on its end point, not where the far start's precision rounds it to. + let far = Polyline { pts: vec![(1e16, 0.0), (1.0, 0.0)], knot: vec![true; 2], closed: false }; + let [(end, dir)] = far.sample(&[far.length()])[..] else { panic!("one sample") }; + assert_eq!(end, (1.0, 0.0)); + assert!(dir.0 < 0.0, "still heading back towards the origin"); } #[test]