geo-index icon indicating copy to clipboard operation
geo-index copied to clipboard

What does nearest neighbor to a point mean in the docs?

Open ogencoglu opened this issue 11 months ago • 3 comments

# Find the nearest neighbors in the RTree to the point (5, 5)
results = rt.neighbors(tree, 5, 5)

What is the definition of nearest (or distance in general) between bounding boxes (rectangles) and a point here?

ogencoglu avatar Jan 09 '25 23:01 ogencoglu

It's the distance to the closest point of the box. If the point is inside the box, it has a distance of 0; otherwise some point on the exterior of the box is used.

This is the function used to find the nearest corner or edge of the box: https://github.com/kylebarron/geo-index/blob/9ca258bf397250c46b52e0abaef47e29a5c71913/src/rtree/trait.rs#L295-L306

(I'm not sure the ordering for nearest boxes when multiple have a distance of 0, maybe it's undefined)

kylebarron avatar Jan 09 '25 23:01 kylebarron

Thanks for the swift reply.

ogencoglu avatar Jan 09 '25 23:01 ogencoglu

We can keep this open to add this explanation to the docs.

kylebarron avatar Jan 09 '25 23:01 kylebarron