public KDTreeNode <TKey, TValue>[] RangeQuery(TKey[] center, TKey radius, int count) { var nearestNeighbours = new NearestNeighbourList <KDTreeNode <TKey, TValue>, TKey>(count, typeMath); AddNearestNeighbours( root, center, KDTreeHyperRect <TKey> .Infinite(dimensions, typeMath), 0, nearestNeighbours, typeMath.Multiply(radius, radius)); count = nearestNeighbours.Count; var neighbourArray = new KDTreeNode <TKey, TValue> [count]; for (var index = 0; index < count; index++) { neighbourArray[count - index - 1] = nearestNeighbours.RemoveFurtherest(); } return(neighbourArray); }
public KDTreeNode <TKey, TValue>[] NearestNeighboursQuery(TKey[] point, int count) { if (count > Count) { count = Count; } if (count < 0) { throw new ArgumentException("Number of neighbors cannot be negative"); } if (count == 0) { return(new KDTreeNode <TKey, TValue> [0]); } var neighbours = new KDTreeNode <TKey, TValue> [count]; var nearestNeighbours = new NearestNeighbourList <KDTreeNode <TKey, TValue>, TKey>(count, typeMath); var rect = KDTreeHyperRect <TKey> .Infinite(dimensions, typeMath); AddNearestNeighbours(root, point, rect, 0, nearestNeighbours, typeMath.MaxValue); count = nearestNeighbours.Count; var neighbourArray = new KDTreeNode <TKey, TValue> [count]; for (var index = 0; index < count; index++) { neighbourArray[count - index - 1] = nearestNeighbours.RemoveFurtherest(); } return(neighbourArray); }