MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / earcut

Function earcut

libs/mapv/mapv.js:1613–1649  ·  view source on GitHub ↗
(data, holeIndices, dim)

Source from the content-addressed store, hash-verified

1611};
1612
1613function earcut(data, holeIndices, dim) {
1614
1615 dim = dim || 2;
1616
1617 var hasHoles = holeIndices && holeIndices.length,
1618 outerLen = hasHoles ? holeIndices[0] * dim : data.length,
1619 outerNode = linkedList(data, 0, outerLen, dim, true),
1620 triangles = [];
1621
1622 if (!outerNode) return triangles;
1623
1624 var minX, minY, maxX, maxY, x, y, size;
1625
1626 if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
1627
1628 // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
1629 if (data.length > 80 * dim) {
1630 minX = maxX = data[0];
1631 minY = maxY = data[1];
1632
1633 for (var i = dim; i < outerLen; i += dim) {
1634 x = data[i];
1635 y = data[i + 1];
1636 if (x < minX) minX = x;
1637 if (y < minY) minY = y;
1638 if (x > maxX) maxX = x;
1639 if (y > maxY) maxY = y;
1640 }
1641
1642 // minX, minY and size are later used to transform coords into integers for z-order calculation
1643 size = Math.max(maxX - minX, maxY - minY);
1644 }
1645
1646 earcutLinked(outerNode, triangles, dim, minX, minY, size);
1647
1648 return triangles;
1649}
1650
1651// create a circular doubly linked list from polygon points in the specified winding order
1652function linkedList(data, start, end, dim, clockwise) {

Callers 1

draw$4Function · 0.85

Calls 4

linkedListFunction · 0.85
eliminateHolesFunction · 0.85
earcutLinkedFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected