Package org.tinfour.utils
Class NearestNeighborPointCollector
- java.lang.Object
-
- org.tinfour.utils.NearestNeighborPointCollector
-
public class NearestNeighborPointCollector extends Object
Provides a utility for the efficient identification of the K-nearest points to a specified set of query coordinates. This utility works by creating a grid of bins into which the vertices are initially separated. The bins are then searched to find the nearest vertices.This class is intended to support testing and verification. It has no direct relationship with any of the graph-based structures produced by the Tinfour library.
The design of this class is optimized for repeated searches of very large vertex sets. While the up front processing is not trivial, the time cost is compensated for by more efficient processing across multiple searches.
-
-
Constructor Summary
Constructors Constructor Description NearestNeighborPointCollector(List<Vertex> vList, boolean mergeDuplicates)Construct a collector based on the specified list of vertices and bounds.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetNearestNeighbors(double x, double y, int k, double[] d, Vertex[] v)Get the K nearest neighbors from the collection.List<Vertex>getVertices()Gets a list of the vertices currently stored in the collection.voidsetResolutionRule(VertexMergerGroup.ResolutionRule rule)Sets the rule for resolving coincident vertices; recalculates value for vertices in the collection, if necessary
-
-
-
Constructor Detail
-
NearestNeighborPointCollector
public NearestNeighborPointCollector(List<Vertex> vList, boolean mergeDuplicates)
Construct a collector based on the specified list of vertices and bounds. It is assumed that the coordinates and values of all specifications are valid floating-point values (no NaN's included).- Parameters:
vList- a list of valid verticesmergeDuplicates- indicates whether duplicates should be merged.
-
-
Method Detail
-
setResolutionRule
public void setResolutionRule(VertexMergerGroup.ResolutionRule rule)
Sets the rule for resolving coincident vertices; recalculates value for vertices in the collection, if necessary- Parameters:
rule- a valid member of the enumeration
-
getNearestNeighbors
public int getNearestNeighbors(double x, double y, int k, double[] d, Vertex[] v)Get the K nearest neighbors from the collection. The- Parameters:
x- the x coordinate of the search positiony- the y coordinate of the search positionk- the target number of vertices to be collectedd- storage for the distances to the vertices to be collected (must be dimensioned at least to size k, but can be larger)v- storage for the vertices to be collected (must be dimensioned at least to size k, but can be larger)- Returns:
- the number of neighboring vertices identified.
-
-