All Projects → mapbox → Earcut.hpp

mapbox / Earcut.hpp

Licence: isc
Fast, header-only polygon triangulation

Programming Languages

c
50402 projects - #5 most used programming language
cpp
1120 projects

Projects that are alternatives of or similar to Earcut.hpp

Cgal
The public CGAL repository, see the README below
Stars: ✭ 2,825 (+531.99%)
Mutual labels:  polygon, geometry, triangulation
Unity.library.eppz.geometry
2D Geometry for Unity. Suited for everyday polygon hassle. Polygon clipping, polygon winding direction, polygon area, polygon centroid, centroid of multiple polygons, line intersection, point-line distance, segment intersection, polygon-point containment, polygon triangulation, polygon Voronoi diagram, polygon offset, polygon outline, polygon buffer, polygon union, polygon substraction, polygon boolean operations, and more. It is a polygon fest.
Stars: ✭ 198 (-55.7%)
Mutual labels:  polygon, geometry, triangulation
Geometry2d
Unity3D: A set of helper classes for 2D geometric calculations.
Stars: ✭ 40 (-91.05%)
Mutual labels:  polygon, geometry, triangulation
Earcut
The fastest and smallest JavaScript polygon triangulation library for your WebGL apps
Stars: ✭ 1,359 (+204.03%)
Mutual labels:  algorithm, polygon, triangulation
osm-static-maps
Openstreetmap static maps is a nodejs lib, CLI and server open source inspired on google static map service
Stars: ✭ 130 (-70.92%)
Mutual labels:  geometry, polygon
wildmeshing-python
Python bindings for TriWild.
Stars: ✭ 37 (-91.72%)
Mutual labels:  geometry, triangulation
EsriRESTScraper
A Python class that scrapes ESRI Rest Endpoints and exports data to a geodatabase
Stars: ✭ 43 (-90.38%)
Mutual labels:  geometry, polygon
polygon-splitter
A small (<10kb minified) javascript library for splitting polygons by a polyline.
Stars: ✭ 20 (-95.53%)
Mutual labels:  geometry, polygon
Rrt Algorithms
n-dimensional RRT, RRT* (RRT-Star)
Stars: ✭ 195 (-56.38%)
Mutual labels:  algorithm, geometry
martinez-src
Mirrored implementations of polygon clipping/CSG/operations algorithm, in C (original, by Martínez et al) and ActionScript3 (port, by Mahir Iqbal)
Stars: ✭ 34 (-92.39%)
Mutual labels:  geometry, polygon
Grass.DirectX
Realistic Grass Rendering using DirectX 11 and a geometry-shader based approach.
Stars: ✭ 56 (-87.47%)
Mutual labels:  geometry, rendering
Shape-Your-Music
A web application for drawing music.
Stars: ✭ 106 (-76.29%)
Mutual labels:  geometry, polygon
SplashGeom
Open-source C++ library for geometry and linear algebra
Stars: ✭ 22 (-95.08%)
Mutual labels:  geometry, triangulation
envelope ex
Utilities for calculating and comparing envelopes from geometries
Stars: ✭ 15 (-96.64%)
Mutual labels:  geometry, polygon
Delaunator Cpp
A really fast C++ library for Delaunay triangulation of 2D points
Stars: ✭ 244 (-45.41%)
Mutual labels:  algorithm, triangulation
geofeatures2
A lightweight, high performance geometry library in Swift.
Stars: ✭ 18 (-95.97%)
Mutual labels:  geometry, polygon
SharpMath2
2D math / geometry collision library for C#, compatable with monogame.
Stars: ✭ 36 (-91.95%)
Mutual labels:  geometry, polygon
pymadcad
Simple yet powerful CAD (Computer Aided Design) library, written with Python.
Stars: ✭ 63 (-85.91%)
Mutual labels:  geometry, rendering
unity-clip-shader
Unity shader and scripts for rendering solid clipped geometry
Stars: ✭ 34 (-92.39%)
Mutual labels:  geometry, rendering
Delaunay Triangulation
C++ version the delaunay triangulation
Stars: ✭ 339 (-24.16%)
Mutual labels:  algorithm, triangulation

Earcut

A C++ port of earcut.js, a fast, header-only polygon triangulation library.

Travis AppVeyor Coverage Coverity Scan Average time to resolve an issue Percentage of issues still open Mourner

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.

It's based on ideas from FIST: Fast Industrial-Strength Triangulation of Polygons by Martin Held and Triangulation by Ear Clipping by David Eberly.

Usage

#include <earcut.hpp>
// The number type to use for tessellation
using Coord = double;

// The index type. Defaults to uint32_t, but you can also pass uint16_t if you know that your
// data won't have more than 65536 vertices.
using N = uint32_t;

// Create array
using Point = std::array<Coord, 2>;
std::vector<std::vector<Point>> polygon;

// Fill polygon structure with actual data. Any winding order works.
// The first polyline defines the main polygon.
polygon.push_back({{100, 0}, {100, 100}, {0, 100}, {0, 0}});
// Following polylines define holes.
polygon.push_back({{75, 25}, {75, 75}, {25, 75}, {25, 25}});

// Run tessellation
// Returns array of indices that refer to the vertices of the input polygon.
// e.g: the index 6 would refer to {25, 75} in this example.
// Three subsequent indices form a triangle. Output triangles are clockwise.
std::vector<N> indices = mapbox::earcut<N>(polygon);

Earcut can triangulate a simple, planar polygon of any winding order including holes. It will even return a robust, acceptable solution for non-simple poygons. Earcut works on a 2D plane. If you have three or more dimensions, you can project them onto a 2D surface before triangulation, or use a more suitable library for the task (e.g CGAL).

It is also possible to use your custom point type as input. There are default accessors defined for std::tuple, std::pair, and std::array. For a custom type (like Clipper's IntPoint type), do this:

// struct IntPoint {
//     int64_t X, Y;
// };

namespace mapbox {
namespace util {

template <>
struct nth<0, IntPoint> {
    inline static auto get(const IntPoint &t) {
        return t.X;
    };
};
template <>
struct nth<1, IntPoint> {
    inline static auto get(const IntPoint &t) {
        return t.Y;
    };
};

} // namespace util
} // namespace mapbox

You can also use a custom container type for your polygon. Similar to std::vector, it has to meet the requirements of Container, in particular size(), empty() and operator[].

example triangulation

Additional build instructions

In case you just want to use the earcut triangulation library; copy and include the header file <earcut.hpp> in your project and follow the steps documented in the section Usage.

If you want to build the test, benchmark and visualization programs instead, follow these instructions:

Dependencies

Before you continue, make sure to have the following tools and libraries installed:

Note: On some operating systems such as Windows, manual steps are required to add cmake and git to your PATH environment variable.

Manual compilation

git clone --recursive https://github.com/mapbox/earcut.hpp.git
cd earcut.hpp
mkdir build
cd build
cmake ..
make
# ./tests
# ./bench
# ./viz

Visual Studio, Eclipse, XCode, ...

git clone --recursive https://github.com/mapbox/earcut.hpp.git
cd earcut.hpp
mkdir project
cd project
cmake .. -G "Visual Studio 14 2015"
::you can also generate projects for "Visual Studio 12 2013", "XCode", "Eclipse CDT4 - Unix Makefiles"

After completion, open the generated project with your IDE.

CLion, Visual Studio 2017

Import the project from https://github.com/mapbox/earcut.hpp.git and you should be good to go!

Status

This is currently based on earcut 2.2.2.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].