Skip to content

Commit 910a1f8

Browse files
committed
reorganize examples
1 parent b59810e commit 910a1f8

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ find_package(Threads REQUIRED)
5151
file(GLOB BENCH_SOURCES bench/*.cpp)
5252
add_executable(bench-tests ${BENCH_SOURCES})
5353

54-
file(GLOB TRIANGULATE_SOURCES examples/triangulate/*.cpp)
55-
add_executable(triangulate ${TRIANGULATE_SOURCES})
54+
#examples
55+
add_executable(triangulate-geojson examples/triangulate_geojson.cpp)
56+
add_executable(basic examples/basic.cpp)
5657

5758

5859
# link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@ delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScr
1616

1717
## Usage
1818

19+
`examples/basic.cpp`
20+
1921
```CPP
2022
#include <delaunator.hpp>
2123
#include <cstdio>
2224

23-
//...
24-
int main(int, char* argv[]) {
25-
//...
26-
std::vector<double> coords = {/* x0, y0, x1, y1, ... */};
25+
int main() {
26+
/* x0, y0, x1, y1, ... */
27+
std::vector<double> coords = {-1, 1, 1, 1, 1, -1, -1, -1};
2728

2829
//triangulation happens here
29-
//note moving points to constructor
30-
delaunator::Delaunator delaunator(coords);
30+
delaunator::Delaunator d(coords);
3131

32-
for(std::size_t i = 0; i < delaunator.triangles.size(); i+=3) {
32+
for(std::size_t i = 0; i < d.triangles.size(); i+=3) {
3333
printf(
3434
"Triangle points: [[%f, %f], [%f, %f], [%f, %f]]\n",
35-
delaunator.coords[2 * delaunator.triangles[i]], //tx0
36-
delaunator.coords[2 * delaunator.triangles[i] + 1], //ty0
37-
delaunator.coords[2 * delaunator.triangles[i + 1]], //tx1
38-
delaunator.coords[2 * delaunator.triangles[i + 1] + 1], //ty1
39-
delaunator.coords[2 * delaunator.triangles[i + 2]], //tx2
40-
delaunator.coords[2 * delaunator.triangles[i + 2] + 1], //ty2
41-
)
35+
d.coords[2 * d.triangles[i]], //tx0
36+
d.coords[2 * d.triangles[i] + 1], //ty0
37+
d.coords[2 * d.triangles[i + 1]], //tx1
38+
d.coords[2 * d.triangles[i + 1] + 1],//ty1
39+
d.coords[2 * d.triangles[i + 2]], //tx2
40+
d.coords[2 * d.triangles[i + 2] + 1] //ty2
41+
);
4242
}
4343
}
4444
```
4545

46-
For full example see `examples/triangulate/main.cpp`
46+
[See more examples here](./examples)
4747

4848
## TODO
4949

examples/basic.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <delaunator.hpp>
2+
#include <cstdio>
3+
4+
int main() {
5+
/* x0, y0, x1, y1, ... */
6+
std::vector<double> coords = {-1, 1, 1, 1, 1, -1, -1, -1};
7+
8+
//triangulation happens here
9+
delaunator::Delaunator d(coords);
10+
11+
for(std::size_t i = 0; i < d.triangles.size(); i+=3) {
12+
printf(
13+
"Triangle points: [[%f, %f], [%f, %f], [%f, %f]]\n",
14+
d.coords[2 * d.triangles[i]], //tx0
15+
d.coords[2 * d.triangles[i] + 1], //ty0
16+
d.coords[2 * d.triangles[i + 1]], //tx1
17+
d.coords[2 * d.triangles[i + 1] + 1],//ty1
18+
d.coords[2 * d.triangles[i + 2]], //tx2
19+
d.coords[2 * d.triangles[i + 2] + 1] //ty2
20+
);
21+
}
22+
}

examples/triangulate/main.cpp renamed to examples/triangulate_geojson.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "rapidjson/document.h"
22
#include "rapidjson/prettywriter.h"
33
#include <delaunator.hpp>
4-
#include "../utils.hpp"
4+
#include "./utils.hpp"
55
#include <cstdio>
66
#include <fstream>
77
#include <vector>

0 commit comments

Comments
 (0)