(ear, triangles, dim, minX, minY, size, pass)
| 1695 | |
| 1696 | // main ear slicing loop which triangulates a polygon (given as a linked list) |
| 1697 | function earcutLinked(ear, triangles, dim, minX, minY, size, pass) { |
| 1698 | if (!ear) return; |
| 1699 | |
| 1700 | // interlink polygon nodes in z-order |
| 1701 | if (!pass && size) indexCurve(ear, minX, minY, size); |
| 1702 | |
| 1703 | var stop = ear, |
| 1704 | prev, |
| 1705 | next; |
| 1706 | |
| 1707 | // iterate through ears, slicing them one by one |
| 1708 | while (ear.prev !== ear.next) { |
| 1709 | prev = ear.prev; |
| 1710 | next = ear.next; |
| 1711 | |
| 1712 | if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) { |
| 1713 | // cut off the triangle |
| 1714 | triangles.push(prev.i / dim); |
| 1715 | triangles.push(ear.i / dim); |
| 1716 | triangles.push(next.i / dim); |
| 1717 | |
| 1718 | removeNode(ear); |
| 1719 | |
| 1720 | // skipping the next vertice leads to less sliver triangles |
| 1721 | ear = next.next; |
| 1722 | stop = next.next; |
| 1723 | |
| 1724 | continue; |
| 1725 | } |
| 1726 | |
| 1727 | ear = next; |
| 1728 | |
| 1729 | // if we looped through the whole remaining polygon and can't find any more ears |
| 1730 | if (ear === stop) { |
| 1731 | // try filtering points and slicing again |
| 1732 | if (!pass) { |
| 1733 | earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1); |
| 1734 | |
| 1735 | // if this didn't work, try curing all small self-intersections locally |
| 1736 | } else if (pass === 1) { |
| 1737 | ear = cureLocalIntersections(ear, triangles, dim); |
| 1738 | earcutLinked(ear, triangles, dim, minX, minY, size, 2); |
| 1739 | |
| 1740 | // as a last resort, try splitting the remaining polygon into two |
| 1741 | } else if (pass === 2) { |
| 1742 | splitEarcut(ear, triangles, dim, minX, minY, size); |
| 1743 | } |
| 1744 | |
| 1745 | break; |
| 1746 | } |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | // check whether a polygon node forms a valid ear with adjacent nodes |
| 1751 | function isEar(ear) { |
no test coverage detected