spatial-index
Spatial index using KD-tree for finding neighbor search.
API
index = spatialIndex(points, metric, dimensions, accuracy)
points
- array of points
metric
- distance function between two points
dimensions
- list of props representing each dimension e.g.:
Array like point [0.3, 0.5] -> [0, 1]
Object like point { x: 0.3, y: 0.5 } -> ['x', 'y']
accuracy
- precision below which points are considered equal
const spatialIndex = const Vec2 = const points = 0 0 1 0 2 1 1 0 0 0 0 2 const index =
index.getUniquePoints()
let uniquePoints = index//[[0, 0], [1, 0], [2, 1], [0, 2]]
index.nearestPoint(p)
let nearest = index//[0, 1]
index.includePoint(p)
index
index.indexOf(p)
let index = index//3 let index = index//-1