reorganize examples
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 45c8ddf..1448879 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,8 +51,9 @@
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
diff --git a/README.md b/README.md
index 301c53f..a61b709 100644
--- a/README.md
+++ b/README.md
@@ -16,34 +16,34 @@
## 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
diff --git a/examples/basic.cpp b/examples/basic.cpp
new file mode 100644
index 0000000..276ceb2
--- /dev/null
+++ b/examples/basic.cpp
@@ -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
+ );
+ }
+}
diff --git a/examples/triangulate/main.cpp b/examples/triangulate_geojson.cpp
similarity index 98%
rename from examples/triangulate/main.cpp
rename to examples/triangulate_geojson.cpp
index fa82383..4c24850 100644
--- a/examples/triangulate/main.cpp
+++ b/examples/triangulate_geojson.cpp
@@ -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>