docs: function polygonQuickDecomp(polygon, result,reflexVertices,steinerPoints,delta,maxlevel,level){
      maxlevel = maxlevel || 100;
      level = level || 0;
      delta = delta || 25;
      result = typeof(result)!=="undefined" ? result : [];
      reflexVertices = reflexVertices || [];
      steinerPoints = steinerPoints || [];
  
      var upperInt=[0,0], lowerInt=[0,0], p=[0,0]; // Points
      var upperDist=0, lowerDist=0, d=0, closestDist=0; // scalars
      var upperIndex=0, lowerIndex=0, closestIndex=0; // Integers
      var lowerPoly=[], upperPoly=[]; // polygons
      var poly = polygon,
          v = polygon;
  
      if(v.length < 3){
  		return result;
      }
  
      level++;
      if(level > maxlevel){
          console.warn("quickDecomp: max level ("+maxlevel+") reached.");
          return result;
      }
  
      for (var i = 0; i < polygon.length; ++i) {
          if (polygonIsReflex(poly, i)) {
              reflexVertices.push(poly[i]);
              upperDist = lowerDist = Number.MAX_VALUE;
  
  
              for (var j = 0; j < polygon.length; ++j) {
                  if (isLeft(polygonAt(poly, i - 1), polygonAt(poly, i), polygonAt(poly, j)) && isRightOn(polygonAt(poly, i - 1), polygonAt(poly, i), polygonAt(poly, j - 1))) { // if line intersects with an edge
                      p = getIntersectionPoint(polygonAt(poly, i - 1), polygonAt(poly, i), polygonAt(poly, j), polygonAt(poly, j - 1)); // find the point of intersection
                      if (isRight(polygonAt(poly, i + 1), polygonAt(poly, i), p)) { // make sure it's inside the poly
                          d = sqdist(poly[i], p);
                          if (d < lowerDist) { // keep only the closest intersection
                              lowerDist = d;
                              lowerInt = p;
                              lowerIndex = j;
                          }
                      }
                  }
                  if (isLeft(polygonAt(poly, i + 1), polygonAt(poly, i), polygonAt(poly, j + 1)) && isRightOn(polygonAt(poly, i + 1), polygonAt(poly, i), polygonAt(poly, j))) {
                      p = getIntersectionPoint(polygonAt(poly, i + 1), polygonAt(poly, i), polygonAt(poly, j), polygonAt(poly, j + 1));
                      if (isLeft(polygonAt(poly, i - 1), polygonAt(poly, i), p)) {
                          d = sqdist(poly[i], p);
                          if (d < upperDist) {
                              upperDist = d;
                              upperInt = p;
                              upperIndex = j;
                          }
                      }
                  }
              }
  
              // if there are no vertices to connect to, choose a point in the middle
              if (lowerIndex === (upperIndex + 1) % polygon.length) {
                  //console.log("Case 1: Vertex("+i+"), lowerIndex("+lowerIndex+"), upperIndex("+upperIndex+"), poly.size("+polygon.length+")");
                  p[0] = (lowerInt[0] + upperInt[0]) / 2;
                  p[1] = (lowerInt[1] + upperInt[1]) / 2;
                  steinerPoints.push(p);
  
                  if (i < upperIndex) {
                      //lowerPoly.insert(lowerPoly.end(), poly.begin() + i, poly.begin() + upperIndex + 1);
                      polygonAppend(lowerPoly, poly, i, upperIndex+1);
                      lowerPoly.push(p);
                      upperPoly.push(p);
                      if (lowerIndex !== 0){
                          //upperPoly.insert(upperPoly.end(), poly.begin() + lowerIndex, poly.end());
                          polygonAppend(upperPoly, poly,lowerIndex,poly.length);
                      }
                      //upperPoly.insert(upperPoly.end(), poly.begin(), poly.begin() + i + 1);
                      polygonAppend(upperPoly, poly,0,i+1);
                  } else {
                      if (i !== 0){
                          //lowerPoly.insert(lowerPoly.end(), poly.begin() + i, poly.end());
                          polygonAppend(lowerPoly, poly,i,poly.length);
                      }
                      //lowerPoly.insert(lowerPoly.end(), poly.begin(), poly.begin() + upperIndex + 1);
                      polygonAppend(lowerPoly, poly,0,upperIndex+1);
                      lowerPoly.push(p);
                      upperPoly.push(p);
                      //upperPoly.insert(upperPoly.end(), poly.begin() + lowerIndex, poly.begin() + i + 1);
                      polygonAppend(upperPoly, poly,lowerIndex,i+1);
                  }
              } else {
                  // connect to the closest point within the triangle
                  //console.log("Case 2: Vertex("+i+"), closestIndex("+closestIndex+"), poly.size("+polygon.length+")\n");
  
                  if (lowerIndex > upperIndex) {
                      upperIndex += polygon.length;
                  }
                  closestDist = Number.MAX_VALUE;
  
                  if(upperIndex < lowerIndex){
                      return result;
                  }
  
                  for (var j = lowerIndex; j <= upperIndex; ++j) {
                      if (
                          isLeftOn(polygonAt(poly, i - 1), polygonAt(poly, i), polygonAt(poly, j)) &&
                          isRightOn(polygonAt(poly, i + 1), polygonAt(poly, i), polygonAt(poly, j))
                      ) {
                          d = sqdist(polygonAt(poly, i), polygonAt(poly, j));
                          if (d < closestDist && polygonCanSee2(poly, i, j)) {
                              closestDist = d;
                              closestIndex = j % polygon.length;
                          }
                      }
                  }
  
                  if (i < closestIndex) {
                      polygonAppend(lowerPoly, poly,i,closestIndex+1);
                      if (closestIndex !== 0){
                          polygonAppend(upperPoly, poly,closestIndex,v.length);
                      }
                      polygonAppend(upperPoly, poly,0,i+1);
                  } else {
                      if (i !== 0){
                          polygonAppend(lowerPoly, poly,i,v.length);
                      }
                      polygonAppend(lowerPoly, poly,0,closestIndex+1);
                      polygonAppend(upperPoly, poly,closestIndex,i+1);
                  }
              }
  
              // solve smallest poly first
              if (lowerPoly.length < upperPoly.length) {
                  polygonQuickDecomp(lowerPoly,result,reflexVertices,steinerPoints,delta,maxlevel,level);
                  polygonQuickDecomp(upperPoly,result,reflexVertices,steinerPoints,delta,maxlevel,level);
              } else {
                  polygonQuickDecomp(upperPoly,result,reflexVertices,steinerPoints,delta,maxlevel,level);
                  polygonQuickDecomp(lowerPoly,result,reflexVertices,steinerPoints,delta,maxlevel,level);
              }
  
              return result;
          }
      }
      result.push(polygon);
  
      return result;
  }