KDBush with flat API, which turns out to be even faster.
constkdgrass=require('kdgrass')letgrass=kdgrass(points);letids1=grass.range(10,10,20,20);// bbox search - minX, minY, maxX, maxYletids2=grass.within(10,10,5);// radius search - x, y, radiusCreates an index from the given points.
points: Input array of points in[x, y, x, y, ...]form.nodeSize: Size of the KD-tree node,64by default. Higher means faster indexing but slower search, and vise versa.
letindex=kdgrass(points,64);Finds all items within the given bounding box and returns an array of indices that refer to the items in the original points input array.
letresults=index.range(10,10,20,20).map((id)=>points[id]);Finds all items within a given radius from the query point and returns an array of indices.
letresults=index.within(10,10,5).map((id)=>points[id]);