0.0.1 • Published 1 year ago

rbush-3d-knn v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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 tree
  • x, y, z: query coordinates
  • k: number of neighbors to search for (Infinity by default)
  • filterFn: optional filter function; k nearest items where filterFn(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