New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kd.tree

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kd.tree

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

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
increased by14.29%
Maintainers
1
Weekly downloads
 
Created
Source

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());

Keywords

FAQs

Package last updated on 22 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc