JSPM

kdt

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3663
  • Score
    100M100P100Q120630F
  • License MIT

100% JS k-d tree. Port of kd-tree-javascript.

Package Exports

  • kdt

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (kdt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Name

kdt

Synopsis

A node.js port of Ubilabs' pure javascript kd-tree library.

Description

This is a fairly straightforward port of the simple & excellent kd-tree javascript library put together by Ubilabs. Their library can be used as-is in node, but this port changes its API to be more node-like and not require calling a new expression. It also wasn't on npm, and everything should be on npm.

Example

var kdt = require('./kdt')

var coords = [
  { name: 'Gramercy Theatre',
    loc: {lat: '40.739683', long: '73.985151'} },
  { name: 'Blue Note Jazz Club',
    loc: {lat: '40.730601', long: '74.000447'} },
  { name: 'Milk Studios',
    loc: {lat: '40.742256', long: '74.006344'} },
  { name: 'Greenroom Brooklyn',
    loc: {lat: '40.691805', long: '73.908089'} }
].map(function (v) {
  return v.loc
})

var distance = function(a, b){
  return Math.pow(a.lat - b.lat, 2) +  Math.pow(a.long - b.long, 2);
}

var tree = kdt.createKdTree(coords, distance, ['lat', 'long'])

var nearest = tree.nearest({ lat: 40, long: 75 }, 4);

console.log(nearest.reverse());