rbush-3d-knn
v0.0.1
Published
k-neareset neighbors search for RBush-3d
Downloads
7
Maintainers
Readme
rbush-3d-knn
k-nearest neighbors search for RBush-3D. Implements a simple depth-first kNN search algorithm using a priority queue.
var RBush = require('rbush-3d');
var knn = require('rbush-knn');
var tree = new RBush(); // create RBush tree
tree.load(data); // bulk insert
var neighbors = knn(tree, 40, 40, 40, 10); // return 10 nearest items around point [40, 40, 40]
You can optionally pass a filter function to find k neighbors that satisfy a certain condition:
var neighbors = knn(tree, 40, 40, 40, 10, function (item) {
return item.foo === 'bar';
});
API
knn(tree, x, y, z, [k, filterFn, maxDistance])
tree
: an RBush treex
,y
,z
: query coordinatesk
: number of neighbors to search for (Infinity
by default)filterFn
: optional filter function;k
nearest items wherefilterFn(item) === true
will be returned.maxDistance
(optional): maximum distance between neighbors and the query coordinates (Infinity
by default)
Changelog
0.0.1 (Nov 12, 2020)
- Rework rbush-knn to work with rbush-3d