/// <summary> /// Finds the nearest rectangles to the passed point. If multiple rectangles are equally near, they will all be returned. /// </summary> /// <param name="p">the point we are looking for</param> /// <param name="furthestDistance">The furthest distance away from the rectangle to search. Rectangles further than this will not be found.</param> /// <returns>a PriorityQue containing the found recatngles and their priorities (distances from point)</returns> public PriorityQueueRTree Nearest(Point p, double furthestDistance) { PriorityQueueRTree distanceQueue = new PriorityQueueRTree(); double furthestDistanceSq = furthestDistance * furthestDistance; rootNode.Nearest(p, this, furthestDistanceSq, distanceQueue); return(distanceQueue); }
internal override double Nearest(Point p, RTree rTree, double furthestDistanceSq, PriorityQueueRTree nearestRectangles) { for (int i = 0; i < entryCount; i++) { double tempDistanceSq = entries[i].Value.distanceSq(p.x, p.y); // a rectangle nearer than actualNearest if (tempDistanceSq <= furthestDistanceSq) { NodeBase node = childNodes[i]; // search the child node furthestDistanceSq = node.Nearest(p, rTree, furthestDistanceSq, nearestRectangles); } } return(furthestDistanceSq); }