godot/thirdparty/misc/patches/polypartition-godot-types.patch

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);