You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Library is ~10% faster then JS version for 1M uniform points ([details](https://github.com/delfrrr/delaunator-cpp/pull/8#issuecomment-422690056))
if (start != INVALID_INDEX && start != hull_next[start]) break;
365
+
}
366
+
367
+
start = hull_prev[start];
368
+
size_t e = start;
369
+
size_t q;
377
370
371
+
while (q = hull_next[e], !orient(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1])) { //TODO: does it works in a same way as in JS
372
+
e = q;
378
373
if (e == start) {
379
-
e = INVALID_INDEX;//TODO: will it work correct?
374
+
e = INVALID_INDEX;
380
375
break;
381
376
}
382
377
}
383
378
384
-
// likely a near-duplicate point; skip it
385
-
if (e == INVALID_INDEX) continue;
386
-
387
-
constbool walk_back = e == start;
379
+
if (e == INVALID_INDEX) continue; // likely a near-duplicate point; skip it
388
380
389
381
// add the first triangle from the point
390
382
std::size_t t = add_triangle(
391
-
m_hull[e].i,
383
+
e,
392
384
i,
393
-
m_hull[m_hull[e].next].i,
385
+
hull_next[e],
394
386
INVALID_INDEX,
395
387
INVALID_INDEX,
396
-
m_hull[e].t);
388
+
hull_tri[e]);
397
389
398
-
m_hull[e].t = t; // keep track of boundary triangles on the hull
399
-
e = insert_node(i, e);
400
-
401
-
// recursively flip triangles from the point until they satisfy the Delaunay condition
402
-
m_hull[e].t = legalize(t + 2);
390
+
hull_tri[i] = legalize(t + 2);
391
+
hull_tri[e] = t;
392
+
hull_size++;
403
393
404
394
// walk forward through the hull, adding more triangles and flipping recursively
405
-
std::size_t q = m_hull[e].next;
406
-
while (orient(
407
-
x, y, //
408
-
m_hull[q].x,
409
-
m_hull[q].y, //
410
-
m_hull[m_hull[q].next].x,
411
-
m_hull[m_hull[q].next].y//
412
-
)) {
413
-
t = add_triangle(
414
-
m_hull[q].i, i, m_hull[m_hull[q].next].i, m_hull[m_hull[q].prev].t, INVALID_INDEX, m_hull[q].t);
415
-
m_hull[m_hull[q].prev].t = legalize(t + 2);
416
-
m_hull_entry = remove_node(q);
417
-
q = m_hull[q].next;
395
+
std::size_t next = hull_next[e];
396
+
while (
397
+
q = hull_next[next],
398
+
orient(x, y, coords[2 * next], coords[2 * next + 1], coords[2 * q], coords[2 * q + 1])) {
399
+
t = add_triangle(next, i, q, hull_tri[i], INVALID_INDEX, hull_tri[next]);
400
+
hull_tri[i] = legalize(t + 2);
401
+
hull_next[next] = next; // mark as removed
402
+
hull_size--;
403
+
next = q;
418
404
}
419
-
if (walk_back) {
420
-
// walk backward from the other side, adding more triangles and flipping
421
-
q = m_hull[e].prev;
422
-
while (orient(
423
-
x, y, //
424
-
m_hull[m_hull[q].prev].x,
425
-
m_hull[m_hull[q].prev].y, //
426
-
m_hull[q].x,
427
-
m_hull[q].y//
428
-
)) {
429
-
t = add_triangle(
430
-
m_hull[m_hull[q].prev].i, i, m_hull[q].i, INVALID_INDEX, m_hull[q].t, m_hull[m_hull[q].prev].t);
405
+
406
+
// walk backward from the other side, adding more triangles and flipping
407
+
if (e == start) {
408
+
while (
409
+
q = hull_prev[e],
410
+
orient(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1])) {
411
+
t = add_triangle(q, i, e, INVALID_INDEX, hull_tri[e], hull_tri[q]);
431
412
legalize(t + 2);
432
-
m_hull[m_hull[q].prev].t = t;
433
-
m_hull_entry = remove_node(q);
434
-
q = m_hull[q].prev;
413
+
hull_tri[q] = t;
414
+
hull_next[e] = e; // mark as removed
415
+
hull_size--;
416
+
e = q;
435
417
}
436
418
}
437
-
hash_edge(e);
438
-
hash_edge(m_hull[e].prev);
419
+
420
+
// update the hull indices
421
+
hull_prev[i] = e;
422
+
hull_start = e;
423
+
hull_prev[next] = i;
424
+
hull_next[e] = i;
425
+
hull_next[i] = next;
426
+
427
+
m_hash[hash_key(x, y)] = i;
428
+
m_hash[hash_key(coords[2 * e], coords[2 * e + 1])] = e;
0 commit comments