Class KNearest<D, T>

A INeighborhood implementation for K-nearest neighbor queries around a given target location, initial query radius and IDistance metric to determine proximity. See Radial for an unbounded and unsorted version.

Remarks

The K-nearest neighbors will be accumulated via an internal Heap and results can be optionally returned in order of proximity (via KNearest.deref or KNearest.values). For K=1 it will be more efficient to use Nearest to avoid the additional overhead.

Type Parameters

  • D

    spatial position for distance metric

  • T

    indexed value

Implements

Constructors

Properties

_currR: number
_heap: Heap<Neighbor<T>> = ...
dist: IDistance<D>

The distance metric used by this neighborhood

k: number
radius: number = Infinity

The neighborhood's original radius (Eucledian metric)

sorted: boolean = false
target: D

The neighborhood's target position / centroid

Methods

  • Computes distance metric between pos and this neighborhood's target pos. If result distance is <= current radius, adds val to neighborhood and shrinks neighborhood radius to new distance. Returns distance metric.

    Parameters

    • pos: D
    • val: T

    Returns number

  • Returns an array of current nearest neighbor result tuples (each [dist, val]). The array will contain at most k items and if the sorted ctor arg was true, will be sorted by distance.

    Returns Neighbor<T>[]

    Remarks

    Use KNearest.values to obtain result values without their distance metrics.

  • Returns true, if distance d is <= current radius of this neighborhood. If eucledian is true (default: true), then d will first be converted into the metric used by this neighborhood using IDistance.to, otherwise it is expected to be already in that metric space.

    Parameters

    • d: number
    • eucledian: boolean = true

    Returns boolean

  • Resets max. search/query radius and clears current results.

    Parameters

    • r: number

    Returns void

Generated using TypeDoc