cureLocalIntersections function

dynamic cureLocalIntersections(
  1. dynamic start,
  2. dynamic triangles,
  3. dynamic dim
)

Implementation

cureLocalIntersections(start, triangles, dim) {
  var p = start;
  do {
    var a = p.prev, b = p.next.next;

    if (!equals(a, b) &&
        intersects(a, p, p.next, b) &&
        locallyInside(a, b) &&
        locallyInside(b, a)) {
      triangles.add(a.i / dim);
      triangles.add(p.i / dim);
      triangles.add(b.i / dim);

      // remove two nodes involved
      removeNode(p);
      removeNode(p.next);

      p = start = b;
    }

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

  return filterPoints(p, null);
}