mapbox_earcut
Python bindings for the C++ implementation of the Mapbox Earcut library, which
provides very fast and quite robust triangulation of 2D polygons.
Original code: earcut.hpp
Original description:
The library implements a modified ear slicing algorithm, optimized by
z-order curve hashing and
extended to handle holes, twisted polygons, degeneracies and self-intersections
in a way that doesn't guarantee correctness of triangulation, but attempts to
always produce acceptable results for practical data like geographical shapes.
Provided functions (depending on dtype of vertex data):
triangulate_float32
triangulate_float64
triangulate_int32
triangulate_int64
Example:
import mapbox_earcut as earcut
import numpy as np
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([3])
result = earcut.triangulate_float32(verts, rings)
print(verts[result])