pub fn simplify_douglas_peucker(
coords: &[GeoCoord],
epsilon: f64,
) -> Vec<GeoCoord>Expand description
Simplify a polyline using the Douglas-Peucker algorithm.
epsilon is the maximum allowed perpendicular distance in degrees
(see module docs for the coordinate-space rationale). Smaller
values retain more detail; zero retains every vertex.
§Returns
A new Vec<GeoCoord> containing only the vertices that exceed the
tolerance threshold, plus the first and last vertices which are
always retained.
§Edge cases
| Input | Result |
|---|---|
| empty slice | empty Vec |
| 1 vertex | that vertex (copied) |
| 2 vertices | both vertices (copied) |
epsilon <= 0.0 | all vertices (no simplification) |
epsilon is NaN | all vertices (no simplification – NaN comparisons always false) |
§Example
use rustial_engine::simplify_douglas_peucker;
use rustial_engine::GeoCoord;
let line = vec![
GeoCoord::from_lat_lon(0.0, 0.0),
GeoCoord::from_lat_lon(0.0, 0.5), // collinear -- will be removed
GeoCoord::from_lat_lon(0.0, 1.0),
];
let simplified = simplify_douglas_peucker(&line, 0.01);
assert_eq!(simplified.len(), 2);