Skip to content

Commit 0e5d18c

Browse files
committed
add documentation
1 parent 319b9c9 commit 0e5d18c

File tree

5 files changed

+48
-45
lines changed

5 files changed

+48
-45
lines changed

CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
cmake_minimum_required(VERSION 3.0.0)
22
project(delaunator VERSION 0.1.0)
3-
set (CMAKE_CXX_STANDARD 17)
3+
set (CMAKE_CXX_STANDARD 14)
44
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/includes")
55
execute_process(COMMAND bash "-c" "(cd ${CMAKE_CURRENT_SOURCE_DIR} && ./fetch-includes.sh)")
66
endif()
7-
# message("PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}")
87

9-
add_executable(main src/main.cpp)
8+
add_executable(triangulate src/triangulate.cpp)
109
add_library(delaunator src/delaunator.cpp)
11-
target_include_directories (main PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
12-
target_include_directories (main PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint")
10+
target_include_directories (triangulate PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
11+
target_include_directories (triangulate PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint")
1312
target_include_directories (delaunator PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
1413
target_include_directories (delaunator PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint")
15-
target_link_libraries(main delaunator)
14+
target_link_libraries(triangulate delaunator)
1615

1716
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
1817
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
19-
# include(CPack)

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"compilerPath": "/usr/bin/clang",
1919
"cStandard": "c11",
20-
"cppStandard": "c++17",
20+
"cppStandard": "c++14",
2121
"intelliSenseMode": "clang-x64",
2222
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
2323
}

README.md

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
11
# delaunator-cpp
22

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

5-
```
6-
{
7-
"configurations": [
8-
{
9-
"name": "CPP Mac",
10-
"includePath": [
11-
"${workspaceFolder}/**",
12-
"/usr/include/**"
13-
],
14-
"defines": [],
15-
"macFrameworkPath": [
16-
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks"
17-
],
18-
"compilerPath": "/usr/bin/clang",
19-
"cStandard": "c11",
20-
"cppStandard": "c++17",
21-
"intelliSenseMode": "clang-x64",
22-
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
23-
}
24-
],
25-
"version": 4
6+
delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScript implementation of very fast 2D Delaunay algorithm.
7+
8+
## Features
9+
10+
* Probably the fastest C++ open source 2D Delaunay implementation
11+
* Roughly 3 times faster then JS version.
12+
* Example showing triangulation of GeoJson points
13+
14+
## Usage
15+
16+
```CPP
17+
#include "delaunator.h"
18+
#include <cstdio>
19+
20+
//...
21+
int main(int, char* argv[]) {
22+
//...
23+
const vector<double> coords = {/* x0, y0, x1, y1, ... */};
24+
Delaunator delaunator(coords); //triangulation happens here
25+
for(long int i = 0; i < delaunator.triangles.size(); i+=3) {
26+
printf(
27+
"Triangle points: [[%f, %f], [%f, %f], [%f, %f]]\n",
28+
delaunator.coords[2 * delaunator.triangles[i]], //tx0
29+
delaunator.coords[2 * delaunator.triangles[i] + 1], //ty0
30+
delaunator.coords[2 * delaunator.triangles[i + 1]], //tx1
31+
delaunator.coords[2 * delaunator.triangles[i + 1] + 1], //ty1
32+
delaunator.coords[2 * delaunator.triangles[i + 2]], //tx2
33+
delaunator.coords[2 * delaunator.triangles[i + 2] + 1], //ty2
34+
)
35+
}
2636
}
27-
```
37+
```
38+
39+
For full example see `src/triangulate.cpp`
40+
41+
## TODO
42+
43+
* Benchmarks
44+
* Unit tests

src/delaunator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <tuple>
77
#include <exception>
88
#include <cmath>
9-
#include "prettyprint.hpp"
9+
// #include "prettyprint.hpp"
1010
#include <iostream>
1111

1212
using namespace std;

src/main.cpp renamed to src/triangulate.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// #include <iostream>
21
#include "rapidjson/document.h"
32
#include "rapidjson/prettywriter.h"
43
#include "delaunator.h"
@@ -8,7 +7,7 @@
87
#include <exception>
98
#include <vector>
109
#include <initializer_list>
11-
#include "prettyprint.hpp"
10+
// #include "prettyprint.hpp"
1211
#include <iostream>
1312
using namespace std;
1413

@@ -42,9 +41,7 @@ namespace {
4241
const double y = coordinates[1].GetDouble();
4342
coords.push_back(x);
4443
coords.push_back(y);
45-
// printf("coordinates %f %f \n", x, y);
4644
}
47-
// Points points = {.x_vector = x_vector, .y_vector = y_vector};
4845
return coords;
4946
}
5047

@@ -115,17 +112,8 @@ int main(int, char* argv[]) {
115112
stream.open(output);
116113
stream << out_json;
117114
stream.close();
118-
// cout << output << endl;
119115
} else {
120116
puts(out_json);
121117
}
122-
123-
// cout << output << endl;
124-
// if (sizeof(argv) > 2) {
125-
// puts("ouput to file");
126-
// } else {
127-
// puts(out_json);
128-
// }
129118
return 0;
130-
// cout << delaunator.triangles << endl;
131119
}

0 commit comments

Comments
 (0)