Skip to content

Commit 32d5793

Browse files
committed
#2 parity with js: mapbox/delaunator@3a61ecc
1 parent 16a5af0 commit 32d5793

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.8)
2-
project(delaunator VERSION 0.2.0)
2+
project(delaunator VERSION 0.3.0)
33
set (CMAKE_CXX_STANDARD 14)
44
set(CMAKE_CXX_STANDARD_REQUIRED on)
55
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScr
1111
## Features
1212

1313
* Probably the fastest C++ open source 2D Delaunay implementation
14-
* Roughly 6 times faster then JS version (more improvements are coming).
14+
* Roughly 6 times faster then JS version `delaunator@v2.0.3`
1515
* Example showing triangulation of GeoJson points
1616

1717
## Usage

bench/benchmark_out.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Run on (4 X 2300 MHz CPU s)
2+
2018-09-18 07:36:59
3+
name,iterations,real_time,cpu_time,time_unit,bytes_per_second,items_per_second,label,error_occurred,error_message
4+
"BM_45K_geojson_nodes",32,22.7033,22.4578,ms,,,,,

generate-reference-triangles/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate-reference-triangles/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"private": true,
44
"main": "index.js",
55
"dependencies": {
6-
"delaunator": "^2.0.2"
6+
"delaunator": "2.0.3"
77
}
88
}

include/delaunator.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ inline bool check_pts_equal(double x1, double y1, double x2, double y2) {
141141
std::fabs(y1 - y2) < std::numeric_limits<double>::epsilon();
142142
}
143143

144+
// monotonically increases with real angle, but doesn't need expensive trigonometry
145+
inline double pseudo_angle(double dx, double dy) {
146+
const double p = dx / (std::abs(dx) + std::abs(dy));
147+
return (dy > 0.0 ? 3.0 - p : 1.0 + p) / 4.0; // [0..1)
148+
}
149+
144150
constexpr std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max();
145151

146152
struct DelaunatorPoint {
@@ -335,6 +341,7 @@ Delaunator::Delaunator(std::vector<double> const& in_coords)
335341
(start == INVALID_INDEX || m_hull[start].removed) &&
336342
(key != start_key));
337343

344+
start = m_hull[start].prev;
338345
e = start;
339346

340347
while (
@@ -497,12 +504,9 @@ std::size_t Delaunator::insert_node(std::size_t i, std::size_t prev) {
497504
std::size_t Delaunator::hash_key(double x, double y) {
498505
const double dx = x - m_center_x;
499506
const double dy = y - m_center_y;
500-
// use pseudo-angle: a measure that monotonically increases
501-
// with real angle, but doesn't require expensive trigonometry
502-
const double p = 1.0 - dx / (std::abs(dx) + std::abs(dy));
503-
return static_cast<std::size_t>(std::llround(std::floor(
504-
(2.0 + (dy < 0.0 ? -p : p)) / 4.0 * static_cast<double>(m_hash_size) //TODO:is this conversion save?
505-
)));
507+
return static_cast<std::size_t>(std::llround(
508+
std::floor(pseudo_angle(dx, dy) * static_cast<double>(m_hash_size))
509+
));
506510
}
507511

508512
void Delaunator::hash_edge(std::size_t e) {

test/test-files/playgrounds-1356-triangles.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)