Skip to main content

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

Project description

# mapbox_earcut

[![Build Status](https://api.travis-ci.org/skogler/mapbox_earcut_python.svg?branch=master)](https://travis-ci.org/skogler/mapbox_earcut_python)

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](https://github.com/mapbox/earcut.hpp)

Original description:

> The library implements a modified ear slicing algorithm, optimized by
> [z-order curve](http://en.wikipedia.org/wiki/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):
```python
triangulate_float32
triangulate_float64
triangulate_int32
triangulate_int64
```

Example:
```python

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.

Source Distribution

mapbox_earcut-0.12.6.tar.gz (556.1 kB view details)

Uploaded Source

File details

Details for the file mapbox_earcut-0.12.6.tar.gz.

File metadata

  • Download URL: mapbox_earcut-0.12.6.tar.gz
  • Upload date:
  • Size: 556.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.4

File hashes

Hashes for mapbox_earcut-0.12.6.tar.gz
Algorithm Hash digest
SHA256 f18438c5f20b8c128c054754d9e9a985af8acb55e1b497b12b4505eb5bc93876
MD5 3939dd423de598039de2981b4361790f
BLAKE2b-256 862026e084cad2839bb0890be283bf157a15eb0cd3707a82f3a89bc4a2a2cb0a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page