d3-geo-voronoi
d3-geo-voronoi copied to clipboard
Faster
Ideas for later:
- change the arrays into typed arrays when possible (edges => edges2, etc) in the delaunay part
use spherical trig for rotation & projection (instead of geoRotation+geoStereographic)✓use spherical trig for checking if a triangle is clockwise or CCW (instead of geoArea!)✓
Another small optimization is using d3.geoStereographicRaw (or inline the definition) instead of d3.geoStereographic.
Skimming through the code, I also recommend:
- Using flat arrays for points — e.g.
[x, y, x, y, ...instead of[[x, y], [x, y], .... - Avoiding array allocations as much as possible. This includes chained
array.mapandslice. Inspect each occurrence of allocating methods and try to rewrite for less allocations (e.g. collapse chained function-style transformation into a single for loop).
https://github.com/Fil/d3-geo-voronoi/commit/4b9aee7f0bfd84cdc962f97e4dc1d2b9e001f926 uses a direct formula for the stereographic
A good reference presentation :) https://www.dotconferences.com/2019/12/vladimir-agafonkin-algorithmic-performance-optimization-in-practice