Skip to main content

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

Project description

mapbox_earcut

Build Status

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

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

print(verts[result])
# [[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.

Files for mapbox-earcut, version 0.12.7
Filename, size File type Python version Upload date Hashes
Filename, size mapbox_earcut-0.12.7-cp35-cp35m-macosx_10_6_intel.whl (54.7 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7-cp35-cp35m-manylinux1_x86_64.whl (67.5 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7-cp35-cp35m-win_amd64.whl (64.3 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7-cp36-cp36m-macosx_10_6_intel.whl (54.7 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7-cp36-cp36m-manylinux1_x86_64.whl (67.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7-cp36-cp36m-win_amd64.whl (64.3 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7-cp37-cp37m-macosx_10_6_intel.whl (54.7 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7-cp37-cp37m-manylinux1_x86_64.whl (67.5 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7-cp37-cp37m-win_amd64.whl (64.3 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size mapbox_earcut-0.12.7.tar.gz (560.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page