Repository navigation
On npm: earstrip@0.2.0.
New
- A constrained Delaunay triangulation for the polygons the ears cannot cut: rings that cross or touch, a hole that cannot be joined to the boundary, and polygons with more than 128 rings. They come back as
Status::Constrained('constrained'in JavaScript), filled inside the outer ring by non-zero winding and outside every hole. On map polygons with broken rings the triangles differ from an even-odd fill of the rings on 0.15% of the pixels on average; earcut's on 31%. - Direct JavaScript calls:
direct.input()anddirect.run()for one polygon,direct.batchInput()anddirect.batch()for many. The polygon is written straight into the module's memory and the result is read there, as strips, a triangle list or one restart index buffer for WebGL 2 or WebGPU; nothing is copied or allocated per polygon. shrink(), in C++ and JavaScript, frees the buffers kept from the largest polygon.- C++:
setConstrained(),setExtraPoints()andextraPoints(). JavaScript:setConstrained(), andstrips()returns the added points aspoints.
Changed
- Where rings cross, the constrained triangulation adds a point next to the crossing. In C++,
strips()andtriangles()can then hold indexn + k(ninput vertices) for pointkofextraPoints();setExtraPoints(false)keeps every index an input vertex. In JavaScript,earstrip(),batch(),direct.batch()and the direct'triangles'never add points. Statushas a new value,Constrained.- The WebAssembly module grows from 56 to 68 KB, 21 to 27 KB with gzip.
Numbers
On 3.7 million map polygons earstrip is 13% faster than earcut.hpp in C++, 1.4 (V8) and 1.6 (JavaScriptCore) times faster than earcut.js through the earcut-compatible call, and 1.7 and 2.1 times through the direct calls; on polygons with thousands of holes, 6 to 7 times. The polygons are in the bench-data-1 release, and Checking the numbers has the command for every row.