earcut (Rust)

July 25, 2026 · View on GitHub

CI codecov Crates.io Version

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

  • Tracks the triangulation behavior and optional Delaunay refinement from the latest earcut 3.2.3.
  • 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 helper, utils3d::project3d_to_2d, projects coplanar 3D polygons onto a 2D plane for use with earcut.

Benchmarks

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

Polygonearcut.hpp (C++)earcut (Rust)
bad_hole2.27 µs/i2.337 µs/i
building294 ns/i167.7 ns/i
degenerate139 ns/i42.63 ns/i
dude4.46 µs/i4.275 µs/i
empty_square271 ns/i83.22 ns/i
water284 µs/i236.2 µs/i
water2192 µs/i155.7 µs/i
water312.8 µs/i13.78 µs/i
water3b1.26 µs/i1.060 µs/i
water453.6 µs/i58.69 µs/i
water_huge1.399 ms/i1.298 ms/i
water_huge22.694 ms/i2.511 ms/i
water_huge321.84 ms/i19.50 ms/i
MVT corpus250 ms/i248 ms/i

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).