Created
April 27, 2021 20:45
-
-
Save steveruizok/5cfc79bd44d7f82296765dc77ba428e7 to your computer and use it in GitHub Desktop.
Streamline a point set, removing irregularities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ## 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