Expand description

simplify-polyline

crates.io latest version crates.io total downloads docs.rs status

A Rust port of the Javascript simplify-js library.

Examples

use simplify_polyline::*;

fn main() {
    let points = [
        Point { vec: [0.0, 0.0] }, Point { vec: [1.0, 1.0] },
        Point { vec: [2.0, 2.0] }, Point { vec: [3.0, 3.0] },
        Point { vec: [4.0, 4.0] }
    ];
    // alternatively, use the point! macro
    let points = [
        point!(0.0, 0.0), point!(1.0, 1.0), point!(2.0, 2.0),
        point!(3.0, 3.0), point!(4.0, 4.0)
    ];
    // alternatively, use the points! macro
    let points = points![(0.0, 0.0), (1.0, 1.0), (2.0, 2.0), (3.0, 3.0), (4.0, 4.0)];

    // low-quality simplification (fast)
    let new_points = simplify(&points, 1.0, false);
    // low-quality simplification (slower)
    let new_points = simplify(&points, 1.0, true);
}

Features

  • serde, optional, defaults to off. Allows serializing/deserializing points.
    • Note, this only works for some dimensions, and some formats. Read the docs for more info.

Performance

Measurements taken with an AMD Ryzen 7 5800x, in Pop!_OS 22.04.

Test Casesimplify-polylinesimplify-js
1118 Points, Low Quality, Tolerance 116.584 μs52.907 μs
1118 Points, High Quality, Tolerance 126.989 μs85.653 μs
1118 Points, Low Quality, Tolerance 53.987 μs12.840 μs
1118 Points, High Quality, Tolerance 519.497 μs57.901 μs
73752 Points, Low Quality, Tolerance 182.251 μs273.075 μs
73752 Points, High Quality, Tolerance 11933.700 μs5376.344 μs
73752 Points, Low Quality, Tolerance 554.150 μs181.554 μs
73752 Points, High Quality, Tolerance 51458.900 μs3921.569 μs

Contributing

Tests

$ cargo test --all-features

or

$ cargo make test

Benchmarks

$ cargo bench --all-features

or

$ cargo make bench

Macros

  • Creates a single Point, where the dimension is determined from the number of values specified, and the values all must implement ExtendedNumOps and be of the same type.
  • Creates a Point array, where the dimension is determined by the length of the tuples in the array, and the values all must implement ExtendedNumOps and be of the same type. Point tuples must all be the same length.

Structs

  • The basic input type for constructing and simplifying a polyline. It can have any number of components, and will work with components that implement the ExtendedNumOps type. Dimensionality must be determined at compile time.

Traits

Functions

  • Simplifies a polyline within a given tolerance.