4 ms·
It’s projecting thousands of sphere geodesics at pixel precision via breaking them into a large number (hundreds of thousands?) of little line segments and eval
by jacobolus 11y ago
It’s projecting thousands of sphere geodesics at pixel precision via breaking them into a large number (hundreds of thousands?) of little line segments and evaluating several expensive nonlinear functions at each of those points with considerable Javascript dataflow overhead for each one, not to mention the cost of putting thousands of polygons with dozens or hundreds of points each into SVG.
It would take either a domain expert or someone willing to spend a few months studying the problem to write an optimized version, but then it could probably be made to run a couple orders of magnitude faster by using slightly coarser approximations for various function evaluations (no need for 10^-15 precision for drawing on screen), or by simplifying the problem to require fewer function evaluations overall (e.g. by using Bézier curve segments instead of straight line segments), rewriting the core of the library to be vectorized, and rendering via a raster- rather than DOM-based drawing system. I’m sure a GPU could handle such a problem very effectively, though working with WebGL might be a pain.
Anyway, go for it!
- y_u_no_rust 11y agoI agree, It would probably run considerably faster if it were written in Rust.
- golergka 11y agoIt runs Voronoi every step instead of building polygons once? Why?
- jacobolus 11y agoNo it does not. Computing the spherical polygons that make up the Voronoi diagram just happens once. The expensive part is rendering them in an arbitrary map projection. Considering this is an orthographic projection, and therefore spherical polygon edges are all ellipses, rendering this picture could certainly be special-cased to only draw ellipses and thereby run much faster. But it’s using a very general D3-geo framework. If you want you can easily tweak the code and the map will be drawn on whatever projection you like. To see some of the possibilities, go to http://bl.ocks.org/mbostock http://bl.ocks.org/mbostock and scroll down a bit.