earcut
earcut copied to clipboard
Multipolygon speed-up
While earcut is great for single polygon calculations, for multipolygon cases it could provide advanced API for more efficient working with Arrays:
- provide input params to work on data range for input data so earcut can work on single big user-pre-allocated array taking its slices (dStar, dEnd)
- provide input params to work on user pre-allocated triangles array as well, saving the results on specified offset and with correct index pointing to the data array being worked from dStart and dEnd.
- return new offset from writing new indices into the triangles.
all above is enabling to efficiently earcut hundreds of thousands polygons and passing the resulting arrays directly into the WebGL buffers.
I did that as experiment and saved hundreds of ms in total (for all polygons processing). Branch of this approach available here : https://github.com/Sumbera/earcut/tree/multipolygon
Another vote for this