Skip to content

ciscorn/earcut

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

earcut (Rust)

CI codecov Crates.io Version

A Rust port of the mapbox/earcut polygon triangulation library.

  • Based on the latest earcut 3.0.2 release.
  • Designed to avoid unnecessary memory allocations. Internal buffers and the output index vector can be reused across multiple triangulations.
  • Also provides earcut::int::EarcutI32 for integer coordinates with exact integer predicates, but it can be slower than the float-based Earcut on modern CPUs.
  • An additional module, utils3d, can project 3D coplanar polygons onto a 2D plane before triangulation.

Benchmarks

Time per iteration (smaller is better). Measured on a MacBook Pro (M1 Pro).

Polygon earcut.hpp (C++) earcut (Rust)
bad_hole 3.53 µs/i 2.712 µs/i
building 351 ns/i 157 ns/i
degenerate 153 ns/i 41 ns/i
dude 5.21 µs/i 4.204 µs/i
empty_square 201 ns/i 67 ns/i
water 420 µs/i 345.8 µs/i
water2 338 µs/i 249.7 µs/i
water3 13.5 µs/i 11.91 µs/i
water3b 1.27 µs/i 1.087 µs/i
water4 88.9 µs/i 67.40 µs/i
water_huge 6.674 ms/i 7.059 ms/i
water_huge2 15.23 ms/i 14.82 ms/i

Note: earcut.hpp has not fully caught up with the latest mapbox/earcut.

Demo

A simple egui-based visualizer for inspecting how earcut works.

cargo run --example visualizer

License

Licensed under either the MIT License (LICENSE-MIT) or the Apache License 2.0 (LICENSE-APACHE) at your option.

This project contains portions derived from mapbox/earcut, originally distributed under the ISC License (LICENSE-ISC).

About

A Rust port of the Earcut polygon triangulation library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Rust 100.0%