Python bindings for the mapbox earcut C++ polygon triangulation library.
Project description
# 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](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.
```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]]
```
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.
```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
Release history Release notifications | RSS feed
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.5.1.tar.gz
(12.6 kB
view hashes)
Built Distributions
Close
Hashes for mapbox_earcut-0.12.5.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 381612510f13e6f89d947da59280e2d9cffaefdcaff2cdd43a062a7422f2b593 |
|
MD5 | 6b0b4b35bfd0f6e0c457672807184888 |
|
BLAKE2b-256 | a05426f465254a3f7d86f3fa8ea5cd44d990aa1d0717585e5b623d1be2767c6e |
Close
Hashes for mapbox_earcut-0.12.5.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 106c24718a6052bb10440f30a796c392a0e26fbeeeef58e9af9d3755c17257cb |
|
MD5 | 85951fa8c1c22beb85216b99ed4ea6c6 |
|
BLAKE2b-256 | bfd33c791d02ee74deddf363e8452d01528df00609e72ad3de889d74d3a28952 |
Close
Hashes for mapbox_earcut-0.12.5.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65a2817dba4e7edd647ed9619f499fcd5b9f9452e19134f157b1446b8e5314d9 |
|
MD5 | aacef2a3dd8fef2c94db0e76eb7938a7 |
|
BLAKE2b-256 | 4d2cc89c247e96a2649c9557d5b7d48d0059f20a1a97b6be36626748a234289d |
Close
Hashes for mapbox_earcut-0.12.5.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dc7241e440952e7381d304fe3d56f11a644f0eb93d28ccc4cf207280c16c3ef |
|
MD5 | 7ee6d3b80d9cfc6900ec52f2a86c5af6 |
|
BLAKE2b-256 | b815990de67c8154ac765f1170c7cbed5efdd6d8ca9c599604b6e682cc1b8999 |
Close
Hashes for mapbox_earcut-0.12.5.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 658ed7787dcfb797ebf2e15c9a6271fbc2c1820a06804878a29bd4baca84f716 |
|
MD5 | fa8cc7ac9ab368503b800b1d5c8b484a |
|
BLAKE2b-256 | 865a81cc4afce5c42123cf414edea03d559b5797e100858fdbc57642eea776ef |
Close
Hashes for mapbox_earcut-0.12.5.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea7ce519e44b2dd1a7cd1d1ef3066dc3a26550912f85aefe545d39e6eb46b7be |
|
MD5 | 108cbefe6c291d0f54896b1f0a654b1b |
|
BLAKE2b-256 | 218313efae2e9d0623900711e84945fec22eea5354f84498b3cc4c7b2ac2819d |