Skip to main content

simplify_path

Function simplify_path 

Source
pub fn simplify_path(path: &Path, tolerance: i64) -> Path
Expand description

Simplifies an open path with the Douglas–Peucker algorithm.

The first and last vertices are always kept and every output vertex is an input vertex. Each removed vertex lies within Euclidean distance tolerance of the output edge that replaces it (compared exactly), so the Hausdorff distance between input and output is at most tolerance. Consecutive duplicate vertices and vertices lying strictly inside the segment joining their neighbours are always removed; with tolerance <= 0 nothing else is.

This is not topology preserving: the output may cross itself where the input did not. Paths with coordinates outside ±MAX_COORD are returned unchanged.