Skip to content

Commit e458e1b

Browse files
committed
#2 parity with js: mapbox/delaunator@760be6b
1 parent b6a57e2 commit e458e1b

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ int main() {
4848

4949
```
5050
Run on (4 X 2300 MHz CPU s)
51-
2018-09-19 09:40:29
51+
2018-09-23 08:36:08
5252
------------------------------------------------------------
5353
Benchmark Time CPU Iterations
5454
------------------------------------------------------------
55-
BM_45K_geojson_nodes 23 ms 23 ms 32
56-
BM_2K_uniform 1 ms 1 ms 970
57-
BM_100K_uniform 63 ms 63 ms 10
58-
BM_200K_uniform 142 ms 141 ms 4
59-
BM_500K_uniform 415 ms 412 ms 2
60-
BM_1M_uniform 1016 ms 1010 ms 1
55+
BM_45K_geojson_nodes 22 ms 22 ms 33
56+
BM_uniform/2000 1 ms 1 ms 953
57+
BM_uniform/100000 61 ms 61 ms 9
58+
BM_uniform/200000 140 ms 140 ms 4
59+
BM_uniform/500000 409 ms 408 ms 2
60+
BM_uniform/1000000 998 ms 995 ms 1
6161
```
6262

6363
Library is ~10% faster then JS version for 1M uniform points ([details](https://github.com/delfrrr/delaunator-cpp/pull/8#issuecomment-422690056))

include/delaunator.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,26 +256,32 @@ Delaunator::Delaunator(std::vector<double> const& in_coords)
256256
}
257257
}
258258

259+
const double i0x = coords[2 * i0];
260+
const double i0y = coords[2 * i0 + 1];
261+
259262
min_dist = std::numeric_limits<double>::max();
260263

261264
// find the point closest to the seed
262265
for (std::size_t i = 0; i < n; i++) {
263266
if (i == i0) continue;
264-
const double d = dist(coords[2 * i0], coords[2 * i0 + 1], coords[2 * i], coords[2 * i + 1]);
267+
const double d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
265268
if (d < min_dist && d > 0.0) {
266269
i1 = i;
267270
min_dist = d;
268271
}
269272
}
270273

274+
double i1x = coords[2 * i1];
275+
double i1y = coords[2 * i1 + 1];
276+
271277
double min_radius = std::numeric_limits<double>::max();
272278

273279
// find the third point which forms the smallest circumcircle with the first two
274280
for (std::size_t i = 0; i < n; i++) {
275281
if (i == i0 || i == i1) continue;
276282

277283
const double r = circumradius(
278-
coords[2 * i0], coords[2 * i0 + 1], coords[2 * i1], coords[2 * i1 + 1], coords[2 * i], coords[2 * i + 1]);
284+
i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
279285

280286
if (r < min_radius) {
281287
i2 = i;
@@ -287,23 +293,15 @@ Delaunator::Delaunator(std::vector<double> const& in_coords)
287293
throw std::runtime_error("not triangulation");
288294
}
289295

290-
if (orient(
291-
coords[2 * i0], coords[2 * i0 + 1], //
292-
coords[2 * i1],
293-
coords[2 * i1 + 1], //
294-
coords[2 * i2],
295-
coords[2 * i2 + 1]) //
296-
) {
296+
double i2x = coords[2 * i2];
297+
double i2y = coords[2 * i2 + 1];
298+
299+
if (orient(i0x, i0y, i1x, i1y, i2x, i2y)) {
297300
std::swap(i1, i2);
301+
std::swap(i1x, i2x);
302+
std::swap(i1y, i2y);
298303
}
299304

300-
const double i0x = coords[2 * i0];
301-
const double i0y = coords[2 * i0 + 1];
302-
const double i1x = coords[2 * i1];
303-
const double i1y = coords[2 * i1 + 1];
304-
const double i2x = coords[2 * i2];
305-
const double i2y = coords[2 * i2 + 1];
306-
307305
std::tie(m_center_x, m_center_y) = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
308306

309307
// sort the points by distance from the seed triangle circumcenter

0 commit comments

Comments
 (0)