Skip to content

Commit 5ba668d

Browse files
authored
Merge pull request #6 from delfrrr/layout-updates
Use mapbox hpp skel
2 parents faaec71 + 90bd235 commit 5ba668d

30 files changed

+1298
-780
lines changed

.clang-format

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Standard: Cpp11
2+
IndentWidth: 4
3+
AccessModifierOffset: -4
4+
UseTab: Never
5+
BinPackParameters: false
6+
BinPackArguments: false
7+
AllowShortIfStatementsOnASingleLine: true
8+
AllowShortLoopsOnASingleLine: false
9+
AllowShortBlocksOnASingleLine: true
10+
AllowShortFunctionsOnASingleLine: false
11+
AllowAllParametersOfDeclarationOnNextLine: true
12+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
13+
AlwaysBreakTemplateDeclarations: true
14+
NamespaceIndentation: None
15+
PointerBindsToType: true
16+
SpacesInParentheses: false
17+
BreakBeforeBraces: Attach
18+
ColumnLimit: 0
19+
Cpp11BracedListStyle: false

.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ CMakeCache.txt
22
CMakeFiles
33
CMakeScripts
44
Testing
5-
Makefile
65
cmake_install.cmake
76
install_manifest.txt
87
compile_commands.json
98
CTestTestfile.cmake
109
.vscode
11-
build
12-
includes
10+
cmake-build
1311
.DS_Store
1412
out
15-
node_modules
13+
node_modules
14+
mason_packages
15+
.toolchain
16+
.mason
17+
local.env

.travis.yml

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,56 @@
1-
language: cpp
2-
dist: trusty
3-
compiler: clang++
4-
os: linux
1+
language: generic
2+
3+
matrix:
4+
include:
5+
# clang-format specific job
6+
- os: linux
7+
sudo: false
8+
env: CLANG_FORMAT
9+
addons:
10+
apt:
11+
sources: [ 'ubuntu-toolchain-r-test' ]
12+
packages: [ 'libstdc++6', 'libstdc++-5-dev' ]
13+
script:
14+
- make format
15+
- os: linux
16+
sudo: false
17+
env: CXX=g++-5
18+
addons:
19+
apt:
20+
sources: [ 'ubuntu-toolchain-r-test' ]
21+
packages: [ 'g++-5' ]
22+
- os: linux
23+
sudo: false
24+
env: CXX=clang++
25+
addons:
26+
apt:
27+
sources: [ 'ubuntu-toolchain-r-test' ]
28+
packages: [ 'libstdc++6', 'libstdc++-5-dev' ]
29+
# disabled before fixing https://github.com/delfrrr/delaunator-cpp/issues/5
30+
# - os: linux
31+
# sudo: required # workaround https://github.com/mapbox/node-cpp-skel/issues/93
32+
# env: CXXFLAGS="-fsanitize=address,undefined,integer -fno-sanitize-recover=all"
33+
# addons:
34+
# apt:
35+
# sources: [ 'ubuntu-toolchain-r-test' ]
36+
# packages: [ 'libstdc++6', 'libstdc++-5-dev' ]
37+
env:
38+
global:
39+
- CMAKE_VERSION="3.8.2"
40+
541
install:
6-
- cmake -DCMAKE_BUILD_TYPE=Release
7-
- VERBOSE=1 make
8-
script: ./delaunator-test
42+
# set up the environment by installing mason and clang++
43+
- ./scripts/setup.sh --config local.env
44+
# put mason and clang++ on PATH
45+
- source local.env
46+
- mason install cmake ${CMAKE_VERSION}
47+
- mason link cmake ${CMAKE_VERSION}
48+
- which cmake
49+
50+
script:
51+
- make release
52+
- make test
53+
- make clean
54+
- make debug
55+
- make test
56+
- make clean

CMakeLists.txt

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,63 @@
1-
cmake_minimum_required(VERSION 3.0.0)
2-
project(delaunator VERSION 0.1.0)
1+
cmake_minimum_required(VERSION 3.8)
2+
project(delaunator VERSION 0.2.0)
33
set (CMAKE_CXX_STANDARD 14)
4-
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/includes")
5-
execute_process(COMMAND bash "-c" "(cd ${CMAKE_CURRENT_SOURCE_DIR} && ./fetch-includes.sh)")
4+
set(CMAKE_CXX_STANDARD_REQUIRED on)
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
7+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mason.cmake)
8+
9+
option(WERROR "Add -Werror flag to build (turns warnings into errors)" ON)
10+
11+
# configure optimization
12+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
13+
set(OPTIMIZATION_FLAGS "-O0 -DDEBUG")
14+
message("-- Configuring debug build")
15+
else()
16+
set(OPTIMIZATION_FLAGS "-O3 -DNDEBUG")
17+
message("-- Configuring release build")
18+
endif()
19+
20+
# Enable extra warnings to adhere to https://github.com/mapbox/cpp/issues/37
21+
set(DESIRED_WARNINGS "-Wall -Wextra -Wconversion -Wunreachable-code -Wuninitialized -pedantic-errors -Wold-style-cast -Wno-error=unused-variable -Wshadow -Wfloat-equal -Weffc++")
22+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
23+
set(DESIRED_WARNINGS "${DESIRED_WARNINGS} -Wmost")
624
endif()
725

8-
#delaunator
9-
add_library(delaunator src/delaunator.cpp)
10-
target_include_directories (delaunator PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
11-
target_include_directories (delaunator PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint")
26+
# Note: -D_GLIBCXX_USE_CXX11_ABI=0 is needed to support mason packages that are precompiled libs
27+
# Currently we only depend on a header only library, but this will help avoid issues when more libs are added via mason
28+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0 ${DESIRED_WARNINGS}")
29+
30+
if (WERROR)
31+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
32+
endif()
33+
34+
# mason_use is a mason function within the mason.cmake file and provides ready-to-go vars, like "STATIC_LIBS" and "INCLUDE_DIRS"
35+
mason_use(catch VERSION 2.4.0 HEADER_ONLY)
36+
include_directories(SYSTEM ${MASON_PACKAGE_catch_INCLUDE_DIRS})
37+
38+
mason_use(rapidjson VERSION 1.1.0 HEADER_ONLY)
39+
include_directories(SYSTEM ${MASON_PACKAGE_rapidjson_INCLUDE_DIRS})
40+
41+
mason_use(benchmark VERSION 1.2.0)
42+
include_directories(SYSTEM ${MASON_PACKAGE_benchmark_INCLUDE_DIRS})
1243

13-
#delaunator
14-
add_library(json-helpers src/json-helpers.cpp)
15-
target_include_directories (json-helpers PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
44+
include_directories("${PROJECT_SOURCE_DIR}/include")
1645

17-
#delaunator-test
18-
add_executable(delaunator-test src/delaunator-test.cpp)
19-
target_link_libraries(delaunator-test delaunator)
20-
target_include_directories (delaunator-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/catch/single_include/catch2")
21-
target_link_libraries(delaunator-test json-helpers)
46+
file(GLOB TEST_SOURCES test/*.cpp)
47+
add_executable(unit-tests ${TEST_SOURCES})
2248

23-
#benchmark
24-
add_executable(benchmark src/benchmark.cpp)
25-
target_link_libraries(benchmark delaunator)
26-
target_link_libraries(benchmark json-helpers)
49+
# libbenchmark.a supports threads and therefore needs pthread support
50+
find_package(Threads REQUIRED)
51+
file(GLOB BENCH_SOURCES bench/*.cpp)
52+
add_executable(bench-tests ${BENCH_SOURCES})
2753

54+
#examples
55+
add_executable(triangulate-geojson examples/triangulate_geojson.cpp)
56+
add_executable(basic examples/basic.cpp)
2857

29-
#triangulate
30-
add_executable(triangulate src/triangulate.cpp)
31-
target_include_directories (triangulate PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/rapidjson/include")
32-
target_include_directories (triangulate PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/includes/prettyprint")
33-
target_link_libraries(triangulate delaunator)
34-
target_link_libraries(triangulate json-helpers)
3558

59+
# link benchmark static library to the bench-tests binary so the bench tests know where to find the benchmark impl code
60+
target_link_libraries(bench-tests ${MASON_PACKAGE_benchmark_STATIC_LIBS} ${CMAKE_THREAD_LIBS_INIT})
3661

3762
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
3863
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
# Whether to turn compiler warnings into errors
3+
export WERROR ?= true
4+
export BUILD_DIR ?= cmake-build
5+
6+
default: release
7+
8+
release:
9+
mkdir -p ./$(BUILD_DIR) && cd ./$(BUILD_DIR) && cmake ../ -DCMAKE_BUILD_TYPE=Release -DWERROR=$(WERROR) && VERBOSE=1 cmake --build .
10+
11+
debug:
12+
mkdir -p ./$(BUILD_DIR) && cd ./$(BUILD_DIR) && cmake ../ -DCMAKE_BUILD_TYPE=Debug -DWERROR=$(WERROR) && VERBOSE=1 cmake --build .
13+
14+
test:
15+
@if [ -f ./$(BUILD_DIR)/unit-tests ]; then ./$(BUILD_DIR)/unit-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi
16+
17+
bench:
18+
@if [ -f ./$(BUILD_DIR)/bench-tests ]; then ./$(BUILD_DIR)/bench-tests; else echo "Please run 'make release' or 'make debug' first" && exit 1; fi
19+
20+
tidy:
21+
@echo "not implmented"
22+
23+
coverage:
24+
@echo "not implmented"
25+
26+
clean:
27+
rm -rf ./$(BUILD_DIR)
28+
# remove remains from running 'make coverage'
29+
rm -f *.profraw
30+
rm -f *.profdata
31+
@echo "run 'make distclean' to also clear mason_packages, .mason, and .toolchain directories"
32+
33+
distclean: clean
34+
rm -rf mason_packages
35+
# remove remains from running './scripts/setup.sh'
36+
rm -rf .mason
37+
rm -rf .toolchain
38+
rm -f local.env
39+
40+
format:
41+
./scripts/format.sh
42+
43+
.PHONY: test bench

README.md

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,41 @@ A really fast C++ library for
66
delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScript implementation of very fast 2D Delaunay algorithm.
77

88
[![Build Status](https://travis-ci.org/delfrrr/delaunator-cpp.svg?branch=master)](https://travis-ci.org/delfrrr/delaunator-cpp)
9+
[![badge](https://mapbox.s3.amazonaws.com/cpp-assets/hpp-skel-badge_blue.svg)](https://github.com/mapbox/hpp-skel)
910

1011
## Features
1112

1213
* Probably the fastest C++ open source 2D Delaunay implementation
13-
* Roughly 3 times faster then JS version.
14+
* Roughly 6 times faster then JS version (more improvements are coming).
1415
* Example showing triangulation of GeoJson points
1516

1617
## Usage
1718

19+
`examples/basic.cpp`
20+
1821
```CPP
19-
#include "delaunator.h"
20-
#include <cstdio>
21-
using namespace std;
22-
//...
23-
int main(int, char* argv[]) {
24-
//...
25-
const vector<double> coords = {/* x0, y0, x1, y1, ... */};
22+
#include <delaunator.hpp>
23+
#include <cstdio>
24+
25+
int main() {
26+
/* x0, y0, x1, y1, ... */
27+
std::vector<double> coords = {-1, 1, 1, 1, 1, -1, -1, -1};
2628

2729
//triangulation happens here
28-
//note moving points to constructor
29-
Delaunator delaunator(move(coords));
30+
delaunator::Delaunator d(coords);
3031

31-
for(long int i = 0; i < delaunator.triangles.size(); i+=3) {
32+
for(std::size_t i = 0; i < d.triangles.size(); i+=3) {
3233
printf(
3334
"Triangle points: [[%f, %f], [%f, %f], [%f, %f]]\n",
34-
delaunator.coords[2 * delaunator.triangles[i]], //tx0
35-
delaunator.coords[2 * delaunator.triangles[i] + 1], //ty0
36-
delaunator.coords[2 * delaunator.triangles[i + 1]], //tx1
37-
delaunator.coords[2 * delaunator.triangles[i + 1] + 1], //ty1
38-
delaunator.coords[2 * delaunator.triangles[i + 2]], //tx2
39-
delaunator.coords[2 * delaunator.triangles[i + 2] + 1], //ty2
40-
)
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+
);
4142
}
4243
}
4344
```
4445

45-
For full example see `src/triangulate.cpp`
46-
47-
## TODO
48-
49-
* Benchmarks
50-
* Unit tests
46+
[See more examples here](./examples)

bench/run.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "../examples/utils.hpp"
2+
#include <benchmark/benchmark.h>
3+
#include <delaunator.hpp>
4+
#include <string>
5+
6+
namespace {
7+
void BM_45K_geojson_nodes(benchmark::State& state) {
8+
std::string points_str = utils::read_file("./test/test-files/osm-nodes-45331-epsg-3857.geojson");
9+
std::vector<double> coords = utils::get_geo_json_points(points_str);
10+
11+
while (state.KeepRunning()) {
12+
delaunator::Delaunator delaunator(coords);
13+
}
14+
}
15+
} // namespace
16+
17+
BENCHMARK(BM_45K_geojson_nodes)->Unit(benchmark::kMillisecond);
18+
19+
BENCHMARK_MAIN()

0 commit comments

Comments
 (0)