Function ramerDouglasPeucker

  • Simplify a line given an array of points and a tolerance using the Ramer-Douglas-Peucker algorithm. The tolerance determines the maximum allowed perpendicular distance from a point to the line segment connecting its neighboring points. Points with a greater distance are included in the simplified line, while points with a smaller distance are excluded.

    This version of the function uses an iterative approach with a stack instead of recursion.

    The iterative approach using a stack doesn't guarantee that the points will be processed in the same order as the recursive approach. Because of the way points are pushed onto the stack, the algorithm could sometimes process points out of order.

    To fix this before returning the final result we sort the simplified points in increasing order of x values before returning them.

    Parameters

    • points: [number, number][]

      The array of points to be simplified

    • tolerance: number

      The maximum allowed perpendicular distance from a point to the line segment connecting its neighboring points

    Returns [number, number][]

    The simplified line as an array of points, it sorts the simplified points in increasing order of x values before returning them.

Generated using TypeDoc