Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
delfrrr committed Aug 29, 2018
1 parent 319b9c9 commit 0e5d18c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 45 deletions.
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
cmake_minimum_required(VERSION 3.0.0)
project(delaunator VERSION 0.1.0)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD 14)
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/includes")
execute_process(COMMAND bash "-c" "(cd ${CMAKE_CURRENT_SOURCE_DIR} && ./fetch-includes.sh)")
endif()
# message("PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}")

add_executable(main src/main.cpp)
add_executable(triangulate src/triangulate.cpp)
add_library(delaunator src/delaunator.cpp)
target_include_directories (main PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
target_include_directories (main PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint")
target_include_directories (triangulate PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
target_include_directories (triangulate PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint")
target_include_directories (delaunator PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
target_include_directories (delaunator PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint")
target_link_libraries(main delaunator)
target_link_libraries(triangulate delaunator)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
# include(CPack)
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"cppStandard": "c++14",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
Expand Down
63 changes: 40 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
# delaunator-cpp

**c_cpp_properties.json**
A really fast C++ library for
[Delaunay triangulation](https://en.wikipedia.org/wiki/Delaunay_triangulation) of 2D points.

```
{
"configurations": [
{
"name": "CPP Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
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

```CPP
#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
2 changes: 1 addition & 1 deletion src/delaunator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <tuple>
#include <exception>
#include <cmath>
#include "prettyprint.hpp"
// #include "prettyprint.hpp"
#include <iostream>

using namespace std;
Expand Down
14 changes: 1 addition & 13 deletions src/main.cpp → src/triangulate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// #include <iostream>
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include "delaunator.h"
Expand All @@ -8,7 +7,7 @@
#include <exception>
#include <vector>
#include <initializer_list>
#include "prettyprint.hpp"
// #include "prettyprint.hpp"
#include <iostream>
using namespace std;

Expand Down Expand Up @@ -42,9 +41,7 @@ namespace {
const double y = coordinates[1].GetDouble();
coords.push_back(x);
coords.push_back(y);
// printf("coordinates %f %f \n", x, y);
}
// Points points = {.x_vector = x_vector, .y_vector = y_vector};
return coords;
}

Expand Down Expand Up @@ -115,17 +112,8 @@ int main(int, char* argv[]) {
stream.open(output);
stream << out_json;
stream.close();
// cout << output << endl;
} else {
puts(out_json);
}

// cout << output << endl;
// if (sizeof(argv) > 2) {
// puts("ouput to file");
// } else {
// puts(out_json);
// }
return 0;
// cout << delaunator.triangles << endl;
}

0 comments on commit 0e5d18c

Please sign in to comment.