add documentation
5 files changed
tree: e904cc35e9873a08549df8e98a73a8ab56a3c93e
  1. src/
  2. test-files/
  3. .gitignore
  4. CMakeLists.txt
  5. CONTRIBUTING.md
  6. fetch-includes.sh
  7. LICENSE
  8. README.md
  9. THIRD-PARTY-NOTICES
README.md

delaunator-cpp

A really fast C++ library for Delaunay triangulation of 2D points.

delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScript implementation of very fast 2D Delaunay algorithm.

Features

  • Probably the fastest C++ open source 2D Delaunay implementation
  • Roughly 3 times faster then JS version.
  • Example showing triangulation of GeoJson points

Usage

#include "delaunator.h"
#include  <cstdio>

//...
int main(int, char* argv[]) {
    //...
    const vector<double> coords = {/* x0, y0, x1, y1, ... */};
    Delaunator delaunator(coords); //triangulation happens here
    for(long int i = 0; i < delaunator.triangles.size(); i+=3) {
        printf(
            "Triangle points: [[%f, %f], [%f, %f], [%f, %f]]\n",
            delaunator.coords[2 * delaunator.triangles[i]],         //tx0
            delaunator.coords[2 * delaunator.triangles[i] + 1],     //ty0
            delaunator.coords[2 * delaunator.triangles[i + 1]],     //tx1
            delaunator.coords[2 * delaunator.triangles[i + 1] + 1], //ty1
            delaunator.coords[2 * delaunator.triangles[i + 2]],     //tx2
            delaunator.coords[2 * delaunator.triangles[i + 2] + 1], //ty2
        )
    }
}

For full example see src/triangulate.cpp

TODO

  • Benchmarks
  • Unit tests