A Swift port of Mapbox's earcut.js polygon triangulation library.
Mapbox's earcut.js is governed by an ISC license while this Swift port is governed by an MIT license.
Add the following dependency
.package(url: "https://github.com/measuredweighed/SwiftEarcut.git", from: "1.0.0"),
Comprehensive documentation for SwiftEarcut can be found on the Swift Package Index (click on Documentation
).
Pass Earcut a flat array of vertex coordinates and optionally include an array of hole indices, and the tesselate function will return a flat array of triangle indices.
let result = Earcut.tesselate(data: [10, 0, 0, 50, 60, 60, 70, 10])
// result: [1, 0, 3, 3, 2, 1]