Batch fix-up: path sampling returns a piece's exact end points (CodeRabbit on #18551)

Far from the origin the blend of a piece's ends loses the near end's digits: a line from (1e16, 0) to (1, 0) sampled
at its length gave (0, 0). The start and the end are now returned as they are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-12-01 03:46:21 +01:00
1 parent ef9a745011
commit 993a0b7ee6
1 file changed
+14 -1
+14 -1
View File
@@ -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]