splitEarcut function

dynamic splitEarcut(
  1. dynamic start,
  2. dynamic triangles,
  3. dynamic dim,
  4. dynamic minX,
  5. dynamic minY,
  6. dynamic invSize,
)

Implementation

splitEarcut(start, triangles, dim, minX, minY, invSize) {
  // look for a valid diagonal that divides the polygon into two
  var a = start;
  do {
    var b = a.next.next;
    while (b != a.prev) {
      if (a.i != b.i && isValidDiagonal(a, b)) {
        // split the polygon in two by the diagonal
        var c = splitPolygon(a, b);

        // filter colinear points around the cuts
        a = filterPoints(a, a.next);
        c = filterPoints(c, c.next);

        // run earcut on each half
        earcutLinked(a, triangles, dim, minX, minY, invSize, null);
        earcutLinked(c, triangles, dim, minX, minY, invSize, null);
        return;
      }

      b = b.next;
    }

    a = a.next;
  } while (a != start);
}