code: function earcutLinked (data, ear, triangles, dim, minX, minY, size, pass) {
    if (!ear) {
      return
    }
  
    // interlink polygon nodes in z-order
    if (!pass && minX !== undefined) {
      indexCurve(data, ear, minX, minY, size)
    }
  
    var stop = ear,
      prev, next
  
    // iterate through ears, slicing them one by one
    while (ear.prev !== ear.next) {
      prev = ear.prev
      next = ear.next
  
      if (isEar(data, ear, minX, minY, size)) {
        // cut off the triangle
        triangles.push(prev.i / dim)
        triangles.push(ear.i / dim)
        triangles.push(next.i / dim)
  
        // remove ear node
        next.prev = prev
        prev.next = next
  
        if (ear.prevZ) {
          ear.prevZ.nextZ = ear.nextZ
        }
        if (ear.nextZ) {
          ear.nextZ.prevZ = ear.prevZ
        }
  
        // skipping the next vertice leads to less sliver triangles
        ear = next.next
        stop = next.next
  
        continue
      }
  
      ear = next
  
      // if we looped through the whole remaining polygon and can't find any more ears
      if (ear === stop) {
        // try filtering points and slicing again
        if (!pass) {
          earcutLinked(data, filterPoints(data, ear), triangles, dim, minX, minY, size, 1)
  
          // if this didn't work, try curing all small self-intersections locally
        } else if (pass === 1) {
          ear = cureLocalIntersections(data, ear, triangles, dim)
          earcutLinked(data, ear, triangles, dim, minX, minY, size, 2)
  
          // as a last resort, try splitting the remaining polygon into two
        } else if (pass === 2) {
          splitEarcut(data, ear, triangles, dim, minX, minY, size)
        }
  
        break
      }
    }
  }
docs: main ear slicing loop which triangulates a polygon (given as a linked list)