Skip to content

Commit

Permalink
reorganize examples
Browse files Browse the repository at this point in the history
  • Loading branch information
delfrrr committed Sep 10, 2018
1 parent b59810e commit 910a1f8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ find_package(Threads REQUIRED)
file(GLOB BENCH_SOURCES bench/*.cpp)
add_executable(bench-tests ${BENCH_SOURCES})

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


# link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScr

## Usage

`examples/basic.cpp`

```CPP
#include <delaunator.hpp>
#include <cstdio>

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

//triangulation happens here
//note moving points to constructor
delaunator::Delaunator delaunator(coords);
delaunator::Delaunator d(coords);

for(std::size_t i = 0; i < delaunator.triangles.size(); i+=3) {
for(std::size_t i = 0; i < d.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
)
d.coords[2 * d.triangles[i]], //tx0
d.coords[2 * d.triangles[i] + 1], //ty0
d.coords[2 * d.triangles[i + 1]], //tx1
d.coords[2 * d.triangles[i + 1] + 1],//ty1
d.coords[2 * d.triangles[i + 2]], //tx2
d.coords[2 * d.triangles[i + 2] + 1] //ty2
);
}
}
```

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

## TODO

Expand Down
22 changes: 22 additions & 0 deletions examples/basic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <delaunator.hpp>
#include <cstdio>

int main() {
/* x0, y0, x1, y1, ... */
std::vector<double> coords = {-1, 1, 1, 1, 1, -1, -1, -1};

//triangulation happens here
delaunator::Delaunator d(coords);

for(std::size_t i = 0; i < d.triangles.size(); i+=3) {
printf(
"Triangle points: [[%f, %f], [%f, %f], [%f, %f]]\n",
d.coords[2 * d.triangles[i]], //tx0
d.coords[2 * d.triangles[i] + 1], //ty0
d.coords[2 * d.triangles[i + 1]], //tx1
d.coords[2 * d.triangles[i + 1] + 1],//ty1
d.coords[2 * d.triangles[i + 2]], //tx2
d.coords[2 * d.triangles[i + 2] + 1] //ty2
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include <delaunator.hpp>
#include "../utils.hpp"
#include "./utils.hpp"
#include <cstdio>
#include <fstream>
#include <vector>
Expand Down

0 comments on commit 910a1f8

Please sign in to comment.