Fall along a run
64-bitThe corner points with the slope applied to the heights.
zᵢ = zᵢ − slope × Σ √(Δx² + Δy²)
Math.hypot for each horizontal leg and a running sum for the fall, all in 64-bit. The filter compares each point with the previous point before filtering, not with the last kept point.
export function withSlope(points, slope) {
const out = [];
let fall = 0;
for (let i = 0; i < points.length; i++) {
const q = points[i];
if (i) { const p = points[i - 1]; fall += (slope || 0) * Math.hypot(q[0] - p[0], q[1] - p[1]); }
out.push([q[0], q[1], (q[2] || 0) - fall]);
}
return out.filter((q, i) => !i || Math.hypot(q[0] - out[i - 1][0], q[1] - out[i - 1][1], q[2] - out[i - 1][2]) > 0.5);
}