• Stars
    star
    207
  • Rank 189,769 (Top 4 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created over 9 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

k-nearest neighbors search (KNN) for RBush

rbush-knn Build Status

k-nearest neighbors search for RBush. Implements a simple depth-first kNN search algorithm using a priority queue.

var RBush = require('rbush');
var knn = require('rbush-knn');

var tree = new RBush(); // create RBush tree
tree.load(data); // bulk insert
var neighbors = knn(tree, 40, 40, 10); // return 10 nearest items around point [40, 40]

You can optionally pass a filter function to find k neighbors that satisfy a certain condition:

var neighbors = knn(tree, 40, 40, 10, function (item) {
    return item.foo === 'bar';
});

API

knn(tree, x, y, [k, filterFn, maxDistance])

  • tree: an RBush tree
  • x, y: 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

3.0.1 (Mar 19, 2020)
  • Breaking: fixed maxDistance argument β€” now it's taken into account correctly (rather than being used as a max squared distance). h/t @AleksandarFaraj
  • Updated dependencies & compatibility with RBush v3.
2.0.0 (Jun 30, 2016)
  • Breaking: updated to be compatible with RBush 2.0.
  • Breaking: signature changed from tree, [x, y], k, filterFn to tree, x, y, k, filterFn
  • Improved performance by ~20%.
1.1.0 (Feb 29, 2015)
  • Add an optional filter function argument.
1.0.2 (Jun 25, 2015)
  • 2.5x performance improvement!
1.0.1 (Jun 10, 2015)
  • Fixed an error when requesting more items than the tree has. #1
1.0.0 (Apr 24, 2015)
  • Initial release.

More Repositories

1

suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
JavaScript
3,056
star
2

rbush

RBush β€” a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles
JavaScript
2,411
star
3

simplify-js

High-performance JavaScript polyline simplification library
JavaScript
2,274
star
4

bullshit.js

A bookmarklet for translating marketing speak into human-readable text. πŸ’©
JavaScript
1,846
star
5

flatbush

A very fast static spatial index for 2D points and rectangles in JavaScript 🌱
JavaScript
1,404
star
6

simpleheat

A tiny JavaScript library for drawing heatmaps with Canvas
JavaScript
927
star
7

dead-simple-grid

Dead Simple Grid is a responsive CSS grid micro framework that is just that. Dead simple.
HTML
747
star
8

kdbush

A fast static index for 2D points
JavaScript
618
star
9

tinyqueue

The smallest and simplest priority queue in JavaScript.
JavaScript
428
star
10

projects

A list of awesome open source projects Volodymyr Agafonkin is involved in.
410
star
11

geokdbush

The fastest spatial index for geographic locations in JavaScript
JavaScript
334
star
12

robust-predicates

Fast robust predicates for computational geometry in JavaScript
JavaScript
296
star
13

road-orientation-map

A visualization of road orientations on an interactive map
JavaScript
295
star
14

delaunator-rs

Fast 2D Delaunay triangulation in Rust. A port of Delaunator.
Rust
201
star
15

tinyjam

A radically simple, zero-configuration static site generator in JavaScript
JavaScript
153
star
16

flatqueue

A very fast and simple JavaScript priority queue
JavaScript
133
star
17

quickselect

A fast selection algorithm in JavaScript.
JavaScript
82
star
18

seidel

[DEPRECATED] A JS polygon triangulation library
JavaScript
82
star
19

icomesh

Fast JavaScript icosphere mesh generation library for WebGL visualizations
JavaScript
53
star
20

bbtree

Self-balancing Binary Search Trees in JavaScript
JavaScript
49
star
21

yeahjs

A tiny, modern, fast EJS templating library
JavaScript
45
star
22

geoflatbush

Geographic kNN extension for Flatbush
JavaScript
43
star
23

kdbush.hpp

A fast static spatial index for 2D points in C++11
C++
33
star
24

worker-data-load

A test that shows the benefit of loading large amounts of data directly in a worker instead of a page.
JavaScript
33
star
25

Leaflet.TouchHover

A plugin for adding hover-like interaction to Leaflet maps on mobile devices
JavaScript
27
star
26

eslint-config-mourner

A strict ESLint config for my JavaScript projects
JavaScript
19
star
27

suncalc-go

SunCalc written in Go
Go
18
star
28

yeahml

A tiny subset of YAML for JavaScript
JavaScript
8
star
29

serenity-tm

Serenity is a light, minimal syntax highlighting theme for Sublime Text and Textmate.
8
star
30

pbf-split

Splits a Node stream of protocol buffer messages
JavaScript
7
star
31

hello-lib

Simple boilerplate for my small JS libraries.
JavaScript
7
star
32

color-metrics

JavaScript
6
star
33

agafonkin.com

My little personal page
HTML
5
star
34

fanny

A simple and fast multilayer feedforward neural network implementation in JS, made for learning purposes.
JavaScript
5
star
35

hain

Hain triangulation algorithm in JS (work in progress)
C++
4
star
36

mourner

2
star
37

mourner.github.com

Nothing here yet.
1
star