@@ -259,15 +259,14 @@ Delaunator::Delaunator(const vector<double> &in_coords) {
259259 hash_edge (e);
260260 m_hull[e].t = 2 ;
261261
262- const size_t max_triangles = 2 * n - 5 ;
262+ const long int max_triangles = 2 * n - 5 ;
263263 triangles.reserve (max_triangles * 3 );
264264 halfedges.reserve (max_triangles * 3 );
265265 add_triangle (i0, i1, i2, -1 , -1 , -1 );
266-
267266 double xp = NAN;
268267 double yp = NAN;
269- for (size_t k = 0 ; k < n; k++) {
270- const size_t i = ids[k];
268+ for (long int k = 0 ; k < n; k++) {
269+ const long int i = ids[k];
271270 const double x = coords[2 * i];
272271 const double y = coords[2 * i + 1 ];
273272 if (x == xp && y == yp) continue ;
@@ -279,8 +278,8 @@ Delaunator::Delaunator(const vector<double> &in_coords) {
279278 (x == i2x && y == i2y)
280279 ) continue ;
281280
282- const size_t start_key = hash_key (x, y);
283- size_t key = start_key;
281+ const long int start_key = hash_key (x, y);
282+ long int key = start_key;
284283 long int start = -1 ;
285284 do {
286285 start = m_hash[key];
@@ -299,10 +298,6 @@ Delaunator::Delaunator(const vector<double> &in_coords) {
299298 m_hull[m_hull[e].next ].x , m_hull[m_hull[e].next ].y
300299 ) >= 0
301300 ) {
302- if (m_hull[e].next == -1 ) {
303- cout << e << endl;
304- }
305-
306301 e = m_hull[e].next ;
307302
308303 if (e == start) {
@@ -313,7 +308,7 @@ Delaunator::Delaunator(const vector<double> &in_coords) {
313308 const bool walk_back = e == start;
314309
315310 // add the first triangle from the point
316- size_t t = add_triangle (
311+ long int t = add_triangle (
317312 m_hull[e].i ,
318313 i,
319314 m_hull[m_hull[e].next ].i ,
@@ -325,11 +320,9 @@ Delaunator::Delaunator(const vector<double> &in_coords) {
325320
326321 // recursively flip triangles from the point until they satisfy the Delaunay condition
327322 m_hull[e].t = legalize (t + 2 );
328-
329323 if (m_hull[m_hull[m_hull[e].prev ].prev ].t == halfedges[t + 1 ]) {
330324 m_hull[m_hull[m_hull[e].prev ].prev ].t = t + 2 ;
331325 }
332-
333326 // walk forward through the hull, adding more triangles and flipping recursively
334327 long int q = m_hull[e].next ;
335328 while (
@@ -348,7 +341,6 @@ Delaunator::Delaunator(const vector<double> &in_coords) {
348341 remove_node (q);
349342 q = m_hull[q].next ;
350343 }
351-
352344 if (walk_back) {
353345 // walk backward from the other side, adding more triangles and flipping
354346 q = m_hull[e].prev ;
@@ -370,22 +362,21 @@ Delaunator::Delaunator(const vector<double> &in_coords) {
370362 q = m_hull[q].prev ;
371363 }
372364 }
373-
374365 hash_edge (e);
375366 hash_edge (m_hull[e].prev );
376367 }
377368
378369};
379370
380- size_t Delaunator::remove_node (size_t node) {
371+ long int Delaunator::remove_node (long int node) {
381372 m_hull[m_hull[node].prev ].next = m_hull[node].next ;
382373 m_hull[m_hull[node].next ].prev = m_hull[node].prev ;
383374 m_hull[node].removed = true ;
384375 return m_hull[node].prev ;
385376}
386377
387- size_t Delaunator::legalize (size_t a) {
388- size_t halfedges_size = halfedges.size ();
378+ long int Delaunator::legalize (long int a) {
379+ long int halfedges_size = halfedges.size ();
389380 const long int b = halfedges[a];
390381
391382 const long int a0 = a - a % 3 ;
@@ -422,16 +413,16 @@ size_t Delaunator::legalize(size_t a) {
422413 return ar;
423414}
424415
425- size_t Delaunator::insert_node (size_t i, size_t prev) {
426- const size_t node = insert_node (i);
416+ long int Delaunator::insert_node (long int i, long int prev) {
417+ const long int node = insert_node (i);
427418 m_hull[node].next = m_hull[prev].next ;
428419 m_hull[node].prev = prev;
429420 m_hull[m_hull[node].next ].prev = node;
430421 m_hull[prev].next = node;
431422 return node;
432423};
433424
434- size_t Delaunator::insert_node (size_t i) {
425+ long int Delaunator::insert_node (long int i) {
435426 long int node = m_hull.size ();
436427 DelaunatorPoint p = {
437428 .i = i,
@@ -445,7 +436,7 @@ size_t Delaunator::insert_node(size_t i) {
445436 return node;
446437}
447438
448- size_t Delaunator::hash_key (double x, double y) {
439+ long int Delaunator::hash_key (double x, double y) {
449440 const double dx = x - m_center_x;
450441 const double dy = y - m_center_y;
451442 // use pseudo-angle: a measure that monotonically increases
@@ -454,15 +445,15 @@ size_t Delaunator::hash_key(double x, double y) {
454445 return floor ((2 + (dy < 0 ? -p : p)) / 4 * m_hash_size);
455446}
456447
457- void Delaunator::hash_edge (size_t e){
448+ void Delaunator::hash_edge (long int e){
458449 m_hash[hash_key (m_hull[e].x , m_hull[e].y )] = e;
459450}
460451
461- size_t Delaunator::add_triangle (
462- size_t i0, size_t i1, size_t i2,
463- size_t a, size_t b, size_t c
452+ long int Delaunator::add_triangle (
453+ long int i0, long int i1, long int i2,
454+ long int a, long int b, long int c
464455) {
465- const size_t t = triangles.size ();
456+ const long int t = triangles.size ();
466457 triangles.push_back (i0);
467458 triangles.push_back (i1);
468459 triangles.push_back (i2);
@@ -472,18 +463,20 @@ size_t Delaunator::add_triangle(
472463 return t;
473464}
474465
475- void Delaunator::link (size_t a, size_t b) {
476- size_t s = halfedges.size ();
466+ void Delaunator::link (long int a, long int b) {
467+ long int s = halfedges.size ();
477468 if (a == s) {
478- halfedges.push_back (a );
469+ halfedges.push_back (b );
479470 } else if (a < s) {
480471 halfedges[a] = b;
481472 } else {
482473 throw runtime_error (" Cannot link edge" );
483474 }
484-
485- if (b > -1 ) {
486- if (b < halfedges.size ()) {
475+ if (b != -1 ) {
476+ long int s = halfedges.size ();
477+ if (b == s) {
478+ halfedges.push_back (a);
479+ } else if (b < s) {
487480 halfedges[b] = a;
488481 } else {
489482 throw runtime_error (" Cannot link edge" );
0 commit comments