mapbox / delaunator

An incredibly fast JavaScript library for Delaunay triangulation of 2D points
https://mapbox.github.io/delaunator/
ISC License
2.33k stars 142 forks source link

Fast constructor. #19

Closed mbostock closed 6 years ago

mbostock commented 6 years ago

This replaces the constructor(points[, getX, getY]) with a faster constructor that takes a pre-built flat array [x0, y0, x1, y1, …]. The slow constructor is now available as Delaunator.from.

This will require a major version bump to 2.0. Fixes #17.

mbostock commented 6 years ago

A subtle point to highlight: Delaunator.from generates a Float64Array for coords rather than the (untyped) Array previously used by new Delaunator. If that’s not desired for some reason, I’m happy to revert that back to a plain Array.

mourner commented 6 years ago

This is exactly how I would implement it after looking at d3-delaunay. Thanks a lot for the PR 👍

Re Float64Array — previously benchmarks showed that performance doesn't noticeably differ from simply using an array and letting V8 figure out the best way to represent it internally. However I'm now seeing an obvious improvement (about 13%) on Node v8 and v9 — perhaps related to changes after transition from Crankshaft to TurboFan.