summaryrefslogtreecommitdiff
path: root/thirdparty/misc/patches/polypartition-godot-types.patch
blob: 5d8aba34371ed1fe1a14972edb317523f2f6a529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
diff --git a/thirdparty/misc/polypartition.cpp b/thirdparty/misc/polypartition.cpp
index 3a8a6efa83..8c5409bf24 100644
--- a/thirdparty/misc/polypartition.cpp
+++ b/thirdparty/misc/polypartition.cpp
@@ -26,7 +26,6 @@
 #include <math.h>
 #include <string.h>
 #include <algorithm>
-#include <vector>
 
 TPPLPoly::TPPLPoly() {
   hole = false;
@@ -186,7 +185,7 @@ int TPPLPartition::Intersects(TPPLPoint &p11, TPPLPoint &p12, TPPLPoint &p21, TP
 // Removes holes from inpolys by merging them with non-holes.
 int TPPLPartition::RemoveHoles(TPPLPolyList *inpolys, TPPLPolyList *outpolys) {
   TPPLPolyList polys;
-  TPPLPolyList::iterator holeiter, polyiter, iter, iter2;
+  TPPLPolyList::Element *holeiter, *polyiter, *iter, *iter2;
   long i, i2, holepointindex, polypointindex;
   TPPLPoint holepoint, polypoint, bestpolypoint;
   TPPLPoint linep1, linep2;
@@ -198,15 +197,15 @@ int TPPLPartition::RemoveHoles(TPPLPolyList *inpolys, TPPLPolyList *outpolys) {
 
   // Check for the trivial case of no holes.
   hasholes = false;
-  for (iter = inpolys->begin(); iter != inpolys->end(); iter++) {
-    if (iter->IsHole()) {
+  for (iter = inpolys->front(); iter; iter = iter->next()) {
+    if (iter->get().IsHole()) {
       hasholes = true;
       break;
     }
   }
   if (!hasholes) {
-    for (iter = inpolys->begin(); iter != inpolys->end(); iter++) {
-      outpolys->push_back(*iter);
+    for (iter = inpolys->front(); iter; iter = iter->next()) {
+      outpolys->push_back(iter->get());
     }
     return 1;
   }
@@ -216,8 +215,8 @@ int TPPLPartition::RemoveHoles(TPPLPolyList *inpolys, TPPLPolyList *outpolys) {
   while (1) {
     // Find the hole point with the largest x.
     hasholes = false;
-    for (iter = polys.begin(); iter != polys.end(); iter++) {
-      if (!iter->IsHole()) {
+    for (iter = polys.front(); iter; iter = iter->next()) {
+      if (!iter->get().IsHole()) {
         continue;
       }
 
@@ -227,8 +226,8 @@ int TPPLPartition::RemoveHoles(TPPLPolyList *inpolys, TPPLPolyList *outpolys) {
         holepointindex = 0;
       }
 
-      for (i = 0; i < iter->GetNumPoints(); i++) {
-        if (iter->GetPoint(i).x > holeiter->GetPoint(holepointindex).x) {
+      for (i = 0; i < iter->get().GetNumPoints(); i++) {
+        if (iter->get().GetPoint(i).x > holeiter->get().GetPoint(holepointindex).x) {
           holeiter = iter;
           holepointindex = i;
         }
@@ -237,24 +236,24 @@ int TPPLPartition::RemoveHoles(TPPLPolyList *inpolys, TPPLPolyList *outpolys) {
     if (!hasholes) {
       break;
     }
-    holepoint = holeiter->GetPoint(holepointindex);
+    holepoint = holeiter->get().GetPoint(holepointindex);
 
     pointfound = false;
-    for (iter = polys.begin(); iter != polys.end(); iter++) {
-      if (iter->IsHole()) {
+    for (iter = polys.front(); iter; iter = iter->next()) {
+      if (iter->get().IsHole()) {
         continue;
       }
-      for (i = 0; i < iter->GetNumPoints(); i++) {
-        if (iter->GetPoint(i).x <= holepoint.x) {
+      for (i = 0; i < iter->get().GetNumPoints(); i++) {
+        if (iter->get().GetPoint(i).x <= holepoint.x) {
           continue;
         }
-        if (!InCone(iter->GetPoint((i + iter->GetNumPoints() - 1) % (iter->GetNumPoints())),
-                    iter->GetPoint(i),
-                    iter->GetPoint((i + 1) % (iter->GetNumPoints())),
+        if (!InCone(iter->get().GetPoint((i + iter->get().GetNumPoints() - 1) % (iter->get().GetNumPoints())),
+                    iter->get().GetPoint(i),
+                    iter->get().GetPoint((i + 1) % (iter->get().GetNumPoints())),
                     holepoint)) {
           continue;
         }
-        polypoint = iter->GetPoint(i);
+        polypoint = iter->get().GetPoint(i);
         if (pointfound) {
           v1 = Normalize(polypoint - holepoint);
           v2 = Normalize(bestpolypoint - holepoint);
@@ -263,13 +262,13 @@ int TPPLPartition::RemoveHoles(TPPLPolyList *inpolys, TPPLPolyList *outpolys) {
           }
         }
         pointvisible = true;
-        for (iter2 = polys.begin(); iter2 != polys.end(); iter2++) {
-          if (iter2->IsHole()) {
+        for (iter2 = polys.front(); iter2; iter2 = iter2->next()) {
+          if (iter2->get().IsHole()) {
             continue;
           }
-          for (i2 = 0; i2 < iter2->GetNumPoints(); i2++) {
-            linep1 = iter2->GetPoint(i2);
-            linep2 = iter2->GetPoint((i2 + 1) % (iter2->GetNumPoints()));
+          for (i2 = 0; i2 < iter2->get().GetNumPoints(); i2++) {
+            linep1 = iter2->get().GetPoint(i2);
+            linep2 = iter2->get().GetPoint((i2 + 1) % (iter2->get().GetNumPoints()));
             if (Intersects(holepoint, polypoint, linep1, linep2)) {
               pointvisible = false;
               break;
@@ -292,18 +291,18 @@ int TPPLPartition::RemoveHoles(TPPLPolyList *inpolys, TPPLPolyList *outpolys) {
       return 0;
     }
 
-    newpoly.Init(holeiter->GetNumPoints() + polyiter->GetNumPoints() + 2);
+    newpoly.Init(holeiter->get().GetNumPoints() + polyiter->get().GetNumPoints() + 2);
     i2 = 0;
     for (i = 0; i <= polypointindex; i++) {
-      newpoly[i2] = polyiter->GetPoint(i);
+      newpoly[i2] = polyiter->get().GetPoint(i);
       i2++;
     }
-    for (i = 0; i <= holeiter->GetNumPoints(); i++) {
-      newpoly[i2] = holeiter->GetPoint((i + holepointindex) % holeiter->GetNumPoints());
+    for (i = 0; i <= holeiter->get().GetNumPoints(); i++) {
+      newpoly[i2] = holeiter->get().GetPoint((i + holepointindex) % holeiter->get().GetNumPoints());
       i2++;
     }
-    for (i = polypointindex; i < polyiter->GetNumPoints(); i++) {
-      newpoly[i2] = polyiter->GetPoint(i);
+    for (i = polypointindex; i < polyiter->get().GetNumPoints(); i++) {
+      newpoly[i2] = polyiter->get().GetPoint(i);
       i2++;
     }
 
@@ -312,8 +311,8 @@ int TPPLPartition::RemoveHoles(TPPLPolyList *inpolys, TPPLPolyList *outpolys) {
     polys.push_back(newpoly);
   }
 
-  for (iter = polys.begin(); iter != polys.end(); iter++) {
-    outpolys->push_back(*iter);
+  for (iter = polys.front(); iter; iter = iter->next()) {
+    outpolys->push_back(iter->get());
   }
 
   return 1;
@@ -524,13 +523,13 @@ int TPPLPartition::Triangulate_EC(TPPLPoly *poly, TPPLPolyList *triangles) {
 
 int TPPLPartition::Triangulate_EC(TPPLPolyList *inpolys, TPPLPolyList *triangles) {
   TPPLPolyList outpolys;
-  TPPLPolyList::iterator iter;
+  TPPLPolyList::Element *iter;
 
   if (!RemoveHoles(inpolys, &outpolys)) {
     return 0;
   }
-  for (iter = outpolys.begin(); iter != outpolys.end(); iter++) {
-    if (!Triangulate_EC(&(*iter), triangles)) {
+  for (iter = outpolys.front(); iter; iter = iter->next()) {
+    if (!Triangulate_EC(&(iter->get()), triangles)) {
       return 0;
     }
   }
@@ -543,7 +542,7 @@ int TPPLPartition::ConvexPartition_HM(TPPLPoly *poly, TPPLPolyList *parts) {
   }
 
   TPPLPolyList triangles;
-  TPPLPolyList::iterator iter1, iter2;
+  TPPLPolyList::Element *iter1, *iter2;
   TPPLPoly *poly1 = NULL, *poly2 = NULL;
   TPPLPoly newpoly;
   TPPLPoint d1, d2, p1, p2, p3;
@@ -578,19 +577,19 @@ int TPPLPartition::ConvexPartition_HM(TPPLPoly *poly, TPPLPolyList *parts) {
     return 0;
   }
 
-  for (iter1 = triangles.begin(); iter1 != triangles.end(); iter1++) {
-    poly1 = &(*iter1);
+  for (iter1 = triangles.front(); iter1; iter1 = iter1->next()) {
+    poly1 = &(iter1->get());
     for (i11 = 0; i11 < poly1->GetNumPoints(); i11++) {
       d1 = poly1->GetPoint(i11);
       i12 = (i11 + 1) % (poly1->GetNumPoints());
       d2 = poly1->GetPoint(i12);
 
       isdiagonal = false;
-      for (iter2 = iter1; iter2 != triangles.end(); iter2++) {
+      for (iter2 = iter1; iter2; iter2 = iter2->next()) {
         if (iter1 == iter2) {
           continue;
         }
-        poly2 = &(*iter2);
+        poly2 = &(iter2->get());
 
         for (i21 = 0; i21 < poly2->GetNumPoints(); i21++) {
           if ((d2.x != poly2->GetPoint(i21).x) || (d2.y != poly2->GetPoint(i21).y)) {
@@ -660,16 +659,16 @@ int TPPLPartition::ConvexPartition_HM(TPPLPoly *poly, TPPLPolyList *parts) {
       }
 
       triangles.erase(iter2);
-      *iter1 = newpoly;
-      poly1 = &(*iter1);
+      iter1->get() = newpoly;
+      poly1 = &(iter1->get());
       i11 = -1;
 
       continue;
     }
   }
 
-  for (iter1 = triangles.begin(); iter1 != triangles.end(); iter1++) {
-    parts->push_back(*iter1);
+  for (iter1 = triangles.front(); iter1; iter1 = iter1->next()) {
+    parts->push_back(iter1->get());
   }
 
   return 1;
@@ -677,13 +676,13 @@ int TPPLPartition::ConvexPartition_HM(TPPLPoly *poly, TPPLPolyList *parts) {
 
 int TPPLPartition::ConvexPartition_HM(TPPLPolyList *inpolys, TPPLPolyList *parts) {
   TPPLPolyList outpolys;
-  TPPLPolyList::iterator iter;
+  TPPLPolyList::Element *iter;
 
   if (!RemoveHoles(inpolys, &outpolys)) {
     return 0;
   }
-  for (iter = outpolys.begin(); iter != outpolys.end(); iter++) {
-    if (!ConvexPartition_HM(&(*iter), parts)) {
+  for (iter = outpolys.front(); iter; iter = iter->next()) {
+    if (!ConvexPartition_HM(&(iter->get()), parts)) {
       return 0;
     }
   }
@@ -824,8 +823,8 @@ int TPPLPartition::Triangulate_OPT(TPPLPoly *poly, TPPLPolyList *triangles) {
   newdiagonal.index1 = 0;
   newdiagonal.index2 = n - 1;
   diagonals.push_back(newdiagonal);
-  while (!diagonals.empty()) {
-    diagonal = *(diagonals.begin());
+  while (!diagonals.is_empty()) {
+    diagonal = diagonals.front()->get();
     diagonals.pop_front();
     bestvertex = dpstates[diagonal.index2][diagonal.index1].bestvertex;
     if (bestvertex == -1) {
@@ -873,10 +872,10 @@ void TPPLPartition::UpdateState(long a, long b, long w, long i, long j, DPState2
     pairs->push_front(newdiagonal);
     dpstates[a][b].weight = w;
   } else {
-    if ((!pairs->empty()) && (i <= pairs->begin()->index1)) {
+    if ((!pairs->is_empty()) && (i <= pairs->front()->get().index1)) {
       return;
     }
-    while ((!pairs->empty()) && (pairs->begin()->index2 >= j)) {
+    while ((!pairs->is_empty()) && (pairs->front()->get().index2 >= j)) {
       pairs->pop_front();
     }
     pairs->push_front(newdiagonal);
@@ -885,7 +884,7 @@ void TPPLPartition::UpdateState(long a, long b, long w, long i, long j, DPState2
 
 void TPPLPartition::TypeA(long i, long j, long k, PartitionVertex *vertices, DPState2 **dpstates) {
   DiagonalList *pairs = NULL;
-  DiagonalList::iterator iter, lastiter;
+  DiagonalList::Element *iter, *lastiter;
   long top;
   long w;
 
@@ -902,23 +901,23 @@ void TPPLPartition::TypeA(long i, long j, long k, PartitionVertex *vertices, DPS
   }
   if (j - i > 1) {
     pairs = &(dpstates[i][j].pairs);
-    iter = pairs->end();
-    lastiter = pairs->end();
-    while (iter != pairs->begin()) {
+    iter = pairs->back();
+    lastiter = pairs->back();
+    while (iter != pairs->front()) {
       iter--;
-      if (!IsReflex(vertices[iter->index2].p, vertices[j].p, vertices[k].p)) {
+      if (!IsReflex(vertices[iter->get().index2].p, vertices[j].p, vertices[k].p)) {
         lastiter = iter;
       } else {
         break;
       }
     }
-    if (lastiter == pairs->end()) {
+    if (lastiter == pairs->back()) {
       w++;
     } else {
-      if (IsReflex(vertices[k].p, vertices[i].p, vertices[lastiter->index1].p)) {
+      if (IsReflex(vertices[k].p, vertices[i].p, vertices[lastiter->get().index1].p)) {
         w++;
       } else {
-        top = lastiter->index1;
+        top = lastiter->get().index1;
       }
     }
   }
@@ -927,7 +926,7 @@ void TPPLPartition::TypeA(long i, long j, long k, PartitionVertex *vertices, DPS
 
 void TPPLPartition::TypeB(long i, long j, long k, PartitionVertex *vertices, DPState2 **dpstates) {
   DiagonalList *pairs = NULL;
-  DiagonalList::iterator iter, lastiter;
+  DiagonalList::Element *iter, *lastiter;
   long top;
   long w;
 
@@ -946,21 +945,21 @@ void TPPLPartition::TypeB(long i, long j, long k, PartitionVertex *vertices, DPS
   if (k - j > 1) {
     pairs = &(dpstates[j][k].pairs);
 
-    iter = pairs->begin();
-    if ((!pairs->empty()) && (!IsReflex(vertices[i].p, vertices[j].p, vertices[iter->index1].p))) {
+    iter = pairs->front();
+    if ((!pairs->is_empty()) && (!IsReflex(vertices[i].p, vertices[j].p, vertices[iter->get().index1].p))) {
       lastiter = iter;
-      while (iter != pairs->end()) {
-        if (!IsReflex(vertices[i].p, vertices[j].p, vertices[iter->index1].p)) {
+      while (iter) {
+        if (!IsReflex(vertices[i].p, vertices[j].p, vertices[iter->get().index1].p)) {
           lastiter = iter;
-          iter++;
+          iter = iter->next();
         } else {
           break;
         }
       }
-      if (IsReflex(vertices[lastiter->index2].p, vertices[k].p, vertices[i].p)) {
+      if (IsReflex(vertices[lastiter->get().index2].p, vertices[k].p, vertices[i].p)) {
         w++;
       } else {
-        top = lastiter->index2;
+        top = lastiter->get().index2;
       }
     } else {
       w++;
@@ -981,11 +980,11 @@ int TPPLPartition::ConvexPartition_OPT(TPPLPoly *poly, TPPLPolyList *parts) {
   DiagonalList diagonals, diagonals2;
   Diagonal diagonal, newdiagonal;
   DiagonalList *pairs = NULL, *pairs2 = NULL;
-  DiagonalList::iterator iter, iter2;
+  DiagonalList::Element *iter, *iter2;
   int ret;
   TPPLPoly newpoly;
-  std::vector<long> indices;
-  std::vector<long>::iterator iiter;
+  List<long> indices;
+  List<long>::Element *iiter;
   bool ijreal, jkreal;
 
   n = poly->GetNumPoints();
@@ -1110,35 +1109,35 @@ int TPPLPartition::ConvexPartition_OPT(TPPLPoly *poly, TPPLPolyList *parts) {
   newdiagonal.index1 = 0;
   newdiagonal.index2 = n - 1;
   diagonals.push_front(newdiagonal);
-  while (!diagonals.empty()) {
-    diagonal = *(diagonals.begin());
+  while (!diagonals.is_empty()) {
+    diagonal = diagonals.front()->get();
     diagonals.pop_front();
     if ((diagonal.index2 - diagonal.index1) <= 1) {
       continue;
     }
     pairs = &(dpstates[diagonal.index1][diagonal.index2].pairs);
-    if (pairs->empty()) {
+    if (pairs->is_empty()) {
       ret = 0;
       break;
     }
     if (!vertices[diagonal.index1].isConvex) {
-      iter = pairs->end();
+      iter = pairs->back();
       iter--;
-      j = iter->index2;
+      j = iter->get().index2;
       newdiagonal.index1 = j;
       newdiagonal.index2 = diagonal.index2;
       diagonals.push_front(newdiagonal);
       if ((j - diagonal.index1) > 1) {
-        if (iter->index1 != iter->index2) {
+        if (iter->get().index1 != iter->get().index2) {
           pairs2 = &(dpstates[diagonal.index1][j].pairs);
           while (1) {
-            if (pairs2->empty()) {
+            if (pairs2->is_empty()) {
               ret = 0;
               break;
             }
-            iter2 = pairs2->end();
+            iter2 = pairs2->back();
             iter2--;
-            if (iter->index1 != iter2->index1) {
+            if (iter->get().index1 != iter2->get().index1) {
               pairs2->pop_back();
             } else {
               break;
@@ -1153,21 +1152,21 @@ int TPPLPartition::ConvexPartition_OPT(TPPLPoly *poly, TPPLPolyList *parts) {
         diagonals.push_front(newdiagonal);
       }
     } else {
-      iter = pairs->begin();
-      j = iter->index1;
+      iter = pairs->front();
+      j = iter->get().index1;
       newdiagonal.index1 = diagonal.index1;
       newdiagonal.index2 = j;
       diagonals.push_front(newdiagonal);
       if ((diagonal.index2 - j) > 1) {
-        if (iter->index1 != iter->index2) {
+        if (iter->get().index1 != iter->get().index2) {
           pairs2 = &(dpstates[j][diagonal.index2].pairs);
           while (1) {
-            if (pairs2->empty()) {
+            if (pairs2->is_empty()) {
               ret = 0;
               break;
             }
-            iter2 = pairs2->begin();
-            if (iter->index2 != iter2->index2) {
+            iter2 = pairs2->front();
+            if (iter->get().index2 != iter2->get().index2) {
               pairs2->pop_front();
             } else {
               break;
@@ -1197,8 +1196,8 @@ int TPPLPartition::ConvexPartition_OPT(TPPLPoly *poly, TPPLPolyList *parts) {
   newdiagonal.index1 = 0;
   newdiagonal.index2 = n - 1;
   diagonals.push_front(newdiagonal);
-  while (!diagonals.empty()) {
-    diagonal = *(diagonals.begin());
+  while (!diagonals.is_empty()) {
+    diagonal = diagonals.front()->get();
     diagonals.pop_front();
     if ((diagonal.index2 - diagonal.index1) <= 1) {
       continue;
@@ -1210,8 +1209,8 @@ int TPPLPartition::ConvexPartition_OPT(TPPLPoly *poly, TPPLPolyList *parts) {
     indices.push_back(diagonal.index2);
     diagonals2.push_front(diagonal);
 
-    while (!diagonals2.empty()) {
-      diagonal = *(diagonals2.begin());
+    while (!diagonals2.is_empty()) {
+      diagonal = diagonals2.front()->get();
       diagonals2.pop_front();
       if ((diagonal.index2 - diagonal.index1) <= 1) {
         continue;
@@ -1220,16 +1219,16 @@ int TPPLPartition::ConvexPartition_OPT(TPPLPoly *poly, TPPLPolyList *parts) {
       jkreal = true;
       pairs = &(dpstates[diagonal.index1][diagonal.index2].pairs);
       if (!vertices[diagonal.index1].isConvex) {
-        iter = pairs->end();
+        iter = pairs->back();
         iter--;
-        j = iter->index2;
-        if (iter->index1 != iter->index2) {
+        j = iter->get().index2;
+        if (iter->get().index1 != iter->get().index2) {
           ijreal = false;
         }
       } else {
-        iter = pairs->begin();
-        j = iter->index1;
-        if (iter->index1 != iter->index2) {
+        iter = pairs->front();
+        j = iter->get().index1;
+        if (iter->get().index1 != iter->get().index2) {
           jkreal = false;
         }
       }
@@ -1253,11 +1252,12 @@ int TPPLPartition::ConvexPartition_OPT(TPPLPoly *poly, TPPLPolyList *parts) {
       indices.push_back(j);
     }
 
-    std::sort(indices.begin(), indices.end());
+    //std::sort(indices.begin(), indices.end());
+    indices.sort();
     newpoly.Init((long)indices.size());
     k = 0;
-    for (iiter = indices.begin(); iiter != indices.end(); iiter++) {
-      newpoly[k] = vertices[*iiter].p;
+    for (iiter = indices.front(); iiter != indices.back(); iiter = iiter->next()) {
+      newpoly[k] = vertices[iiter->get()].p;
       k++;
     }
     parts->push_back(newpoly);
@@ -1281,7 +1281,7 @@ int TPPLPartition::ConvexPartition_OPT(TPPLPoly *poly, TPPLPolyList *parts) {
 // "Computational Geometry: Algorithms and Applications"
 // by Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars.
 int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monotonePolys) {
-  TPPLPolyList::iterator iter;
+  TPPLPolyList::Element *iter;
   MonotoneVertex *vertices = NULL;
   long i, numvertices, vindex, vindex2, newnumvertices, maxnumvertices;
   long polystartindex, polyendindex;
@@ -1291,11 +1291,8 @@ int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monoto
   bool error = false;
 
   numvertices = 0;
-  for (iter = inpolys->begin(); iter != inpolys->end(); iter++) {
-    if (!iter->Valid()) {
-      return 0;
-    }
-    numvertices += iter->GetNumPoints();
+  for (iter = inpolys->front(); iter; iter = iter->next()) {
+    numvertices += iter->get().GetNumPoints();
   }
 
   maxnumvertices = numvertices * 3;
@@ -1303,8 +1300,8 @@ int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monoto
   newnumvertices = numvertices;
 
   polystartindex = 0;
-  for (iter = inpolys->begin(); iter != inpolys->end(); iter++) {
-    poly = &(*iter);
+  for (iter = inpolys->front(); iter; iter = iter->next()) {
+    poly = &(iter->get());
     polyendindex = polystartindex + poly->GetNumPoints() - 1;
     for (i = 0; i < poly->GetNumPoints(); i++) {
       vertices[i + polystartindex].p = poly->GetPoint(i);
@@ -1360,14 +1357,14 @@ int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monoto
   // Note that while set doesn't actually have to be implemented as
   // a tree, complexity requirements for operations are the same as
   // for the balanced binary search tree.
-  std::set<ScanLineEdge> edgeTree;
+  Set<ScanLineEdge> edgeTree;
   // Store iterators to the edge tree elements.
   // This makes deleting existing edges much faster.
-  std::set<ScanLineEdge>::iterator *edgeTreeIterators, edgeIter;
-  edgeTreeIterators = new std::set<ScanLineEdge>::iterator[maxnumvertices];
-  std::pair<std::set<ScanLineEdge>::iterator, bool> edgeTreeRet;
+  Set<ScanLineEdge>::Element **edgeTreeIterators, *edgeIter;
+  edgeTreeIterators = new Set<ScanLineEdge>::Element *[maxnumvertices];
+  //Pair<Set<ScanLineEdge>::iterator, bool> edgeTreeRet;
   for (i = 0; i < numvertices; i++) {
-    edgeTreeIterators[i] = edgeTree.end();
+    edgeTreeIterators[i] = nullptr;
   }
 
   // For each vertex.
@@ -1387,13 +1384,14 @@ int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monoto
         newedge.p1 = v->p;
         newedge.p2 = vertices[v->next].p;
         newedge.index = vindex;
-        edgeTreeRet = edgeTree.insert(newedge);
-        edgeTreeIterators[vindex] = edgeTreeRet.first;
+        //edgeTreeRet = edgeTree.insert(newedge);
+        //edgeTreeIterators[vindex] = edgeTreeRet.first;
+        edgeTreeIterators[vindex] = edgeTree.insert(newedge);
         helpers[vindex] = vindex;
         break;
 
       case TPPL_VERTEXTYPE_END:
-        if (edgeTreeIterators[v->previous] == edgeTree.end()) {
+        if (edgeTreeIterators[v->previous] == edgeTree.back()) {
           error = true;
           break;
         }
@@ -1412,29 +1410,30 @@ int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monoto
         newedge.p1 = v->p;
         newedge.p2 = v->p;
         edgeIter = edgeTree.lower_bound(newedge);
-        if (edgeIter == edgeTree.begin()) {
+        if (edgeIter == nullptr || edgeIter == edgeTree.front()) {
           error = true;
           break;
         }
         edgeIter--;
         // Insert the diagonal connecting vi to helper(e_j) in D.
-        AddDiagonal(vertices, &newnumvertices, vindex, helpers[edgeIter->index],
+        AddDiagonal(vertices, &newnumvertices, vindex, helpers[edgeIter->get().index],
                 vertextypes, edgeTreeIterators, &edgeTree, helpers);
         vindex2 = newnumvertices - 2;
         v2 = &(vertices[vindex2]);
         // helper(e_j) in v_i.
-        helpers[edgeIter->index] = vindex;
+        helpers[edgeIter->get().index] = vindex;
         // Insert e_i in T and set helper(e_i) to v_i.
         newedge.p1 = v2->p;
         newedge.p2 = vertices[v2->next].p;
         newedge.index = vindex2;
-        edgeTreeRet = edgeTree.insert(newedge);
-        edgeTreeIterators[vindex2] = edgeTreeRet.first;
+        //edgeTreeRet = edgeTree.insert(newedge);
+        //edgeTreeIterators[vindex2] = edgeTreeRet.first;
+        edgeTreeIterators[vindex2] = edgeTree.insert(newedge);
         helpers[vindex2] = vindex2;
         break;
 
       case TPPL_VERTEXTYPE_MERGE:
-        if (edgeTreeIterators[v->previous] == edgeTree.end()) {
+        if (edgeTreeIterators[v->previous] == edgeTree.back()) {
           error = true;
           break;
         }
@@ -1452,25 +1451,25 @@ int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monoto
         newedge.p1 = v->p;
         newedge.p2 = v->p;
         edgeIter = edgeTree.lower_bound(newedge);
-        if (edgeIter == edgeTree.begin()) {
+        if (edgeIter == nullptr || edgeIter == edgeTree.front()) {
           error = true;
           break;
         }
         edgeIter--;
         // If helper(e_j) is a merge vertex.
-        if (vertextypes[helpers[edgeIter->index]] == TPPL_VERTEXTYPE_MERGE) {
+        if (vertextypes[helpers[edgeIter->get().index]] == TPPL_VERTEXTYPE_MERGE) {
           // Insert the diagonal connecting v_i to helper(e_j) in D.
-          AddDiagonal(vertices, &newnumvertices, vindex2, helpers[edgeIter->index],
+          AddDiagonal(vertices, &newnumvertices, vindex2, helpers[edgeIter->get().index],
                   vertextypes, edgeTreeIterators, &edgeTree, helpers);
         }
         // helper(e_j) <- v_i
-        helpers[edgeIter->index] = vindex2;
+        helpers[edgeIter->get().index] = vindex2;
         break;
 
       case TPPL_VERTEXTYPE_REGULAR:
         // If the interior of P lies to the right of v_i.
         if (Below(v->p, vertices[v->previous].p)) {
-          if (edgeTreeIterators[v->previous] == edgeTree.end()) {
+          if (edgeTreeIterators[v->previous] == edgeTree.back()) {
             error = true;
             break;
           }
@@ -1488,27 +1487,28 @@ int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monoto
           newedge.p1 = v2->p;
           newedge.p2 = vertices[v2->next].p;
           newedge.index = vindex2;
-          edgeTreeRet = edgeTree.insert(newedge);
-          edgeTreeIterators[vindex2] = edgeTreeRet.first;
+          //edgeTreeRet = edgeTree.insert(newedge);
+          //edgeTreeIterators[vindex2] = edgeTreeRet.first;
+          edgeTreeIterators[vindex2] = edgeTree.insert(newedge);
           helpers[vindex2] = vindex;
         } else {
           // Search in T to find the edge e_j directly left of v_i.
           newedge.p1 = v->p;
           newedge.p2 = v->p;
           edgeIter = edgeTree.lower_bound(newedge);
-          if (edgeIter == edgeTree.begin()) {
+          if (edgeIter == nullptr || edgeIter == edgeTree.front()) {
             error = true;
             break;
           }
-          edgeIter--;
+          edgeIter = edgeIter->prev();
           // If helper(e_j) is a merge vertex.
-          if (vertextypes[helpers[edgeIter->index]] == TPPL_VERTEXTYPE_MERGE) {
+          if (vertextypes[helpers[edgeIter->get().index]] == TPPL_VERTEXTYPE_MERGE) {
             // Insert the diagonal connecting v_i to helper(e_j) in D.
-            AddDiagonal(vertices, &newnumvertices, vindex, helpers[edgeIter->index],
+            AddDiagonal(vertices, &newnumvertices, vindex, helpers[edgeIter->get().index],
                     vertextypes, edgeTreeIterators, &edgeTree, helpers);
           }
           // helper(e_j) <- v_i.
-          helpers[edgeIter->index] = vindex;
+          helpers[edgeIter->get().index] = vindex;
         }
         break;
     }
@@ -1569,8 +1569,8 @@ int TPPLPartition::MonotonePartition(TPPLPolyList *inpolys, TPPLPolyList *monoto
 
 // Adds a diagonal to the doubly-connected list of vertices.
 void TPPLPartition::AddDiagonal(MonotoneVertex *vertices, long *numvertices, long index1, long index2,
-        TPPLVertexType *vertextypes, std::set<ScanLineEdge>::iterator *edgeTreeIterators,
-        std::set<ScanLineEdge> *edgeTree, long *helpers) {
+        TPPLVertexType *vertextypes, Set<ScanLineEdge>::Element **edgeTreeIterators,
+        Set<ScanLineEdge> *edgeTree, long *helpers) {
   long newindex1, newindex2;
 
   newindex1 = *numvertices;
@@ -1597,14 +1597,14 @@ void TPPLPartition::AddDiagonal(MonotoneVertex *vertices, long *numvertices, lon
   vertextypes[newindex1] = vertextypes[index1];
   edgeTreeIterators[newindex1] = edgeTreeIterators[index1];
   helpers[newindex1] = helpers[index1];
-  if (edgeTreeIterators[newindex1] != edgeTree->end()) {
-    edgeTreeIterators[newindex1]->index = newindex1;
+  if (edgeTreeIterators[newindex1] != edgeTree->back()) {
+    edgeTreeIterators[newindex1]->get().index = newindex1;
   }
   vertextypes[newindex2] = vertextypes[index2];
   edgeTreeIterators[newindex2] = edgeTreeIterators[index2];
   helpers[newindex2] = helpers[index2];
-  if (edgeTreeIterators[newindex2] != edgeTree->end()) {
-    edgeTreeIterators[newindex2]->index = newindex2;
+  if (edgeTreeIterators[newindex2] != edgeTree->back()) {
+    edgeTreeIterators[newindex2]->get().index = newindex2;
   }
 }
 
@@ -1830,13 +1830,13 @@ int TPPLPartition::TriangulateMonotone(TPPLPoly *inPoly, TPPLPolyList *triangles
 
 int TPPLPartition::Triangulate_MONO(TPPLPolyList *inpolys, TPPLPolyList *triangles) {
   TPPLPolyList monotone;
-  TPPLPolyList::iterator iter;
+  TPPLPolyList::Element *iter;
 
   if (!MonotonePartition(inpolys, &monotone)) {
     return 0;
   }
-  for (iter = monotone.begin(); iter != monotone.end(); iter++) {
-    if (!TriangulateMonotone(&(*iter), triangles)) {
+  for (iter = monotone.front(); iter; iter = iter->next()) {
+    if (!TriangulateMonotone(&(iter->get()), triangles)) {
       return 0;
     }
   }
diff --git a/thirdparty/misc/polypartition.h b/thirdparty/misc/polypartition.h
index f163f5d217..b2d905a3ef 100644
--- a/thirdparty/misc/polypartition.h
+++ b/thirdparty/misc/polypartition.h
@@ -24,8 +24,9 @@
 #ifndef POLYPARTITION_H
 #define POLYPARTITION_H
 
-#include <list>
-#include <set>
+#include "core/math/vector2.h"
+#include "core/templates/list.h"
+#include "core/templates/set.h"
 
 typedef double tppl_float;
 
@@ -44,49 +45,7 @@ enum TPPLVertexType {
 };
 
 // 2D point structure.
-struct TPPLPoint {
-  tppl_float x;
-  tppl_float y;
-  // User-specified vertex identifier. Note that this isn't used internally
-  // by the library, but will be faithfully copied around.
-  int id;
-
-  TPPLPoint operator+(const TPPLPoint &p) const {
-    TPPLPoint r;
-    r.x = x + p.x;
-    r.y = y + p.y;
-    return r;
-  }
-
-  TPPLPoint operator-(const TPPLPoint &p) const {
-    TPPLPoint r;
-    r.x = x - p.x;
-    r.y = y - p.y;
-    return r;
-  }
-
-  TPPLPoint operator*(const tppl_float f) const {
-    TPPLPoint r;
-    r.x = x * f;
-    r.y = y * f;
-    return r;
-  }
-
-  TPPLPoint operator/(const tppl_float f) const {
-    TPPLPoint r;
-    r.x = x / f;
-    r.y = y / f;
-    return r;
-  }
-
-  bool operator==(const TPPLPoint &p) const {
-    return ((x == p.x) && (y == p.y));
-  }
-
-  bool operator!=(const TPPLPoint &p) const {
-    return !((x == p.x) && (y == p.y));
-  }
-};
+typedef Vector2 TPPLPoint;
 
 // Polygon implemented as an array of points with a "hole" flag.
 class TPPLPoly {
@@ -168,9 +127,9 @@ class TPPLPoly {
 };
 
 #ifdef TPPL_ALLOCATOR
-typedef std::list<TPPLPoly, TPPL_ALLOCATOR(TPPLPoly)> TPPLPolyList;
+typedef List<TPPLPoly, TPPL_ALLOCATOR(TPPLPoly)> TPPLPolyList;
 #else
-typedef std::list<TPPLPoly> TPPLPolyList;
+typedef List<TPPLPoly> TPPLPolyList;
 #endif
 
 class TPPLPartition {
@@ -209,9 +168,9 @@ public:
   };
 
 #ifdef TPPL_ALLOCATOR
-  typedef std::list<Diagonal, TPPL_ALLOCATOR(Diagonal)> DiagonalList;
+  typedef List<Diagonal, TPPL_ALLOCATOR(Diagonal)> DiagonalList;
 #else
-  typedef std::list<Diagonal> DiagonalList;
+  typedef List<Diagonal> DiagonalList;
 #endif
 
   // Dynamic programming state for minimum-weight triangulation.
@@ -265,8 +224,8 @@ public:
   // Helper functions for MonotonePartition.
   bool Below(TPPLPoint &p1, TPPLPoint &p2);
   void AddDiagonal(MonotoneVertex *vertices, long *numvertices, long index1, long index2,
-          TPPLVertexType *vertextypes, std::set<ScanLineEdge>::iterator *edgeTreeIterators,
-          std::set<ScanLineEdge> *edgeTree, long *helpers);
+          TPPLVertexType *vertextypes, Set<ScanLineEdge>::Element **edgeTreeIterators,
+          Set<ScanLineEdge> *edgeTree, long *helpers);
 
   // Triangulates a monotone polygon, used in Triangulate_MONO.
   int TriangulateMonotone(TPPLPoly *inPoly, TPPLPolyList *triangles);