| Crates.io | ramer_douglas_peucker |
| lib.rs | ramer_douglas_peucker |
| version | 0.2.4 |
| created_at | 2020-09-11 19:29:46.185107+00 |
| updated_at | 2025-11-29 05:09:59.977543+00 |
| description | An implementation of the Ramer Douglas Peucker algorithm. |
| homepage | https://git.sr.ht/~halzy/ramer_douglas_peucker |
| repository | https://git.sr.ht/~halzy/ramer_douglas_peucker |
| max_upload_size | |
| id | 287485 |
| size | 14,248 |
An implementation of the Ramer-Douglas-Peucker algorithm for curve simplification.
Given a slice of Point2 and an epsilon, the rdp() function returns a Vec<usize> of indices to keep.
use mint::Point2;
use ramer_douglas_peucker::rdp;
let points = vec![
Point2 { x: 0.0, y: 0.0 },
Point2 { x: 1.0, y: 0.5 },
Point2 { x: 2.0, y: -0.9 },
Point2 { x: 3.0, y: 0.3 },
Point2 { x: 4.0, y: 0.0 },
];
let indices = rdp(&points, 1.0);
// Returns vec![0, 4] - only the first and last points are kept
// because all intermediate points are within epsilon of the line
rdp<T, U>(points: &[Point2<T>], epsilon: f64) -> Vec<usize>Simplifies a curve by removing points that are within epsilon distance of the line between neighboring kept points.
Parameters:
points - A slice of mint::Point2<T> representing the curveepsilon - Maximum distance threshold; points closer than this to the simplified line are removedReturns:
Vec<usize> containing the indices of points to keepNotes:
Copy, Sub, NumCast)MIT