Skip to content

Instantly share code, notes, and snippets.

@steveruizok
Created April 27, 2021 20:45
Show Gist options
  • Save steveruizok/5cfc79bd44d7f82296765dc77ba428e7 to your computer and use it in GitHub Desktop.
Save steveruizok/5cfc79bd44d7f82296765dc77ba428e7 to your computer and use it in GitHub Desktop.
Streamline a point set, removing irregularities.
/**
* ## getStreamlinedPoints
* @description Streamline a point set, removing irregularities.
* @param points An array of points (as `[x, y]`).
* @returns number[][]
*/
export function getStreamlinedPoints(points: number[][], streamline = 0.5) {
return points.reduce<number[][]>((acc, cur, i, arr) => {
if (i === 0) {
acc.push(cur)
return acc
}
acc.push(vec.lrp(arr[i - 1], cur, 1 - streamline))
return acc
}, [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment