ramer_douglas_peucker

Crates.ioramer_douglas_peucker
lib.rsramer_douglas_peucker
version0.2.4
created_at2020-09-11 19:29:46.185107+00
updated_at2025-11-29 05:09:59.977543+00
descriptionAn implementation of the Ramer Douglas Peucker algorithm.
homepagehttps://git.sr.ht/~halzy/ramer_douglas_peucker
repositoryhttps://git.sr.ht/~halzy/ramer_douglas_peucker
max_upload_size
id287485
size14,248
Benjamin Halsted (halzy)

documentation

README

ramer_douglas_peucker

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.

Usage

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

API

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 curve
  • epsilon - Maximum distance threshold; points closer than this to the simplified line are removed

Returns:

  • A Vec<usize> containing the indices of points to keep

Notes:

  • If the first and last points are the same, the points are treated as a closed polygon
  • Works with any numeric type that implements the required traits (Copy, Sub, NumCast)

License

MIT

Commit count: 0

cargo fmt