Have ideas to improve npm?Join in the discussion! »

    simplify-path

    1.1.0 • Public • Published

    simplify-path

    stable

    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 = require('simplify-path')
     
    //our input polyline
    var path = [ [250, 150], [250, 150], [25, 25], [24, 25], [10, 10] ]
    var tolerance = 10
     
    //result
    path = simplify(path, tolerance)

    Result:

    [ [ 250, 150 ], [ 25, 25 ], [ 10, 10 ] ]
    

    Or you can use the algorithms individually:

    var path2 = simplify.radialDistance(path, tolerance)
    var path3 = simplify.douglasPeucker(path, tolerance)

    You can also require each algorithm separately:

    var simplify1 = require('simplify-path/radial-distance')
    var simplify2 = require('simplify-path/douglas-peucker')

    Note: For performance, this does not produce a deep copy of the input.

    Usage

    NPM

    simplify(path, tolerance)

    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.

    simplify.radialDistance(path, tolerance)

    Like above, but using only the Radial Distance algorithm.

    simplify.douglasPeucker(path, tolerance)

    Like above, but using only the Douglas-Peucker algorithm.

    License

    MIT, see LICENSE.md for details.

    Install

    npm i simplify-path

    DownloadsWeekly Downloads

    933

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • avatar