5 releases (3 breaking)
0.4.0 | Oct 27, 2022 |
---|---|
0.3.0 | Oct 25, 2022 |
0.2.1 | Oct 20, 2022 |
0.2.0 | Oct 12, 2022 |
0.1.0 | Oct 6, 2022 |
#263 in Math
33 downloads per month
185KB
114 lines
simplify-polyline
A nearly line-by-line Rust port of the Javascript simplify-js library.
Examples
use simplify_polyline::*;
fn main() {
let points = &[
Point { x: 0.0, y: 0.0 }, Point { x: 1.0, y: 1.0 },
Point { x: 2.0, y: 2.0 }, Point { x: 3.0, y: 3.0 },
Point { x: 4.0, y: 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);
}
Performance
Measurements taken with an AMD Ryzen 7 5800x, in Pop!_OS 22.04.
Test Case | simplify-polyline | simplify-js |
---|---|---|
1118 Points, Low Quality, Tolerance 1 | 16.584 μs | 52.907 μs |
1118 Points, High Quality, Tolerance 1 | 30.910 μs | 85.653 μs |
1118 Points, Low Quality, Tolerance 5 | 3.987 μs | 12.840 μs |
1118 Points, High Quality, Tolerance 5 | 23.215 μs | 57.901 μs |
73752 Points, Low Quality, Tolerance 1 | 82.251 μs | 273.075 μs |
73752 Points, High Quality, Tolerance 1 | 1974.004 μs | 5376.344 μs |
73752 Points, Low Quality, Tolerance 5 | 54.150 μs | 181.554 μs |
73752 Points, High Quality, Tolerance 5 | 1460.742 μs | 3921.569 μs |
Contributing
Running tests:
$ cargo test --features tests
Running benchmarks:
$ cargo +nightly bench --features tests