Simplifies a 2D polyline, first using a radial distance check, and then a recursive Douglas-Peucker algorithm. The code is from simplify-js, but uses arrays for better interoperability with npm modules like stack.gl, parse-svg-path, chaikin-smooth, ndarray, etc.
var simplify =//our input polylinevar path = 250 150 250 150 25 25 24 25 10 10var tolerance = 10//resultpath =
[ [ 250, 150 ], [ 25, 25 ], [ 10, 10 ] ]
Or you can use the algorithms individually:
var path2 = simplifyvar path3 = simplify
You can also require each algorithm separately:
var simplify1 =var simplify2 =
Note: For performance, this does not produce a deep copy of the input.
Simplifies the input path with the specified tolerance, removing redundant points first using radial distance, then Douglas-Peucker algorithm. Returns an array of simplified points.
Like above, but using only the Radial Distance algorithm.
Like above, but using only the Douglas-Peucker algorithm.
MIT, see LICENSE.md for details.