Skip to content

Commit

Permalink
#2 parity with js: mapbox/delaunator@3a61ecc
Browse files Browse the repository at this point in the history
  • Loading branch information
delfrrr committed Sep 18, 2018
1 parent 16a5af0 commit 32d5793
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(delaunator VERSION 0.2.0)
project(delaunator VERSION 0.3.0)
set (CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScr
## Features

* Probably the fastest C++ open source 2D Delaunay implementation
* Roughly 6 times faster then JS version (more improvements are coming).
* Roughly 6 times faster then JS version `[email protected]`
* Example showing triangulation of GeoJson points

## Usage
Expand Down
4 changes: 4 additions & 0 deletions bench/benchmark_out.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Run on (4 X 2300 MHz CPU s)
2018-09-18 07:36:59
name,iterations,real_time,cpu_time,time_unit,bytes_per_second,items_per_second,label,error_occurred,error_message
"BM_45K_geojson_nodes",32,22.7033,22.4578,ms,,,,,
6 changes: 3 additions & 3 deletions generate-reference-triangles/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generate-reference-triangles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"private": true,
"main": "index.js",
"dependencies": {
"delaunator": "^2.0.2"
"delaunator": "2.0.3"
}
}
16 changes: 10 additions & 6 deletions include/delaunator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ inline bool check_pts_equal(double x1, double y1, double x2, double y2) {
std::fabs(y1 - y2) < std::numeric_limits<double>::epsilon();
}

// monotonically increases with real angle, but doesn't need expensive trigonometry
inline double pseudo_angle(double dx, double dy) {
const double p = dx / (std::abs(dx) + std::abs(dy));
return (dy > 0.0 ? 3.0 - p : 1.0 + p) / 4.0; // [0..1)
}

constexpr std::size_t INVALID_INDEX = std::numeric_limits<std::size_t>::max();

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

start = m_hull[start].prev;
e = start;

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

void Delaunator::hash_edge(std::size_t e) {
Expand Down
2 changes: 1 addition & 1 deletion test/test-files/playgrounds-1356-triangles.json

Large diffs are not rendered by default.

0 comments on commit 32d5793

Please sign in to comment.