simplify_polyline
Removes the points of a polyline that change its shape by less than tolerance, with the
Ramer–Douglas–Peucker algorithm: each removed point is at most tolerance away from the
simplified line. It shrinks map outlines or traced paths by orders of magnitude while keeping
their look.
The first and last points are always kept. With a tolerance of 0.0, only points exactly on
a straight line are removed. It is iterative, so very long polylines cannot overflow the stack.
Import
Section titled “Import”Cargo feature geometry (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
points | &[Point] | The polyline. |
tolerance | f64 | The maximum distance between a removed point and the result, in the units of the points. |
Returns
Section titled “Returns”Option<Vec<Point>> — The kept points in their original order, or None when tolerance is negative or NaN.
