Skip to main content

Python bindings for the mapbox earcut C++ polygon triangulation library.

Project description


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



import mapbox_earcut as earcut
import numpy as np

# A Nx2 array of vertices. Must be 2D.
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)

# An array of end-indices for each ring.
# The first ring is the outer contour of the polygon.
# Subsequent ones are holes.
# This implies that the last index must always be equal to the size of verts!
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)

# Result is an np.ndarray with dtype np.uint32 and shape (3,)
# containing indices into the verts array.

# [[1 0]
#  [1 1]
#  [0 0]]

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mapbox_earcut-1.0.1.tar.gz (11.8 kB view hashes)

Uploaded source

Built Distributions

mapbox_earcut-1.0.1-cp311-cp311-win32.whl (62.7 kB view hashes)

Uploaded cp311

mapbox_earcut-1.0.1-cp310-cp310-win32.whl (62.8 kB view hashes)

Uploaded cp310

mapbox_earcut-1.0.1-cp39-cp39-win32.whl (62.8 kB view hashes)

Uploaded cp39

mapbox_earcut-1.0.1-cp38-cp38-win32.whl (62.7 kB view hashes)

Uploaded cp38

mapbox_earcut-1.0.1-cp37-cp37m-win32.whl (63.0 kB view hashes)

Uploaded cp37

mapbox_earcut-1.0.1-cp36-cp36m-win32.whl (63.1 kB view hashes)

Uploaded cp36

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page