private TKey DistanceSquaredBetweenPoints(TKey[] a, TKey[] b) { TKey distance = typeMath.Zero; // Return the absolute distance bewteen 2 hyper points for (var dimension = 0; dimension < dimensions; dimension++) { TKey distOnThisAxis = typeMath.Subtract(a[dimension], b[dimension]); TKey distOnThisAxisSquared = typeMath.Multiply(distOnThisAxis, distOnThisAxis); distance = typeMath.Add(distance, distOnThisAxisSquared); } return(distance); }
private KdTreeNode <TKey, TValue>[] RadialSearch(TKey[] center, TKey radius, NearestNeighbourList <KdTreeNode <TKey, TValue>, TKey> nearestNeighbours) { AddNearestNeighbours( root, center, HyperRect <TKey> .Infinite(dimensions, typeMath), 0, nearestNeighbours, typeMath.Multiply(radius, radius)); var 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>[] 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); }