Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ogencoglu opened this issue Jan 9, 2025 · 3 comments
Open

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

ogencoglu opened this issue Jan 9, 2025 · 3 comments

Comments

@ogencoglu
Copy link

# 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?

@kylebarron
Copy link
Owner

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:

/// 1D distance from a value to a range.
#[allow(dead_code)]
#[inline]
fn axis_dist<N: IndexableNum>(k: N, min: N, max: N) -> N {
if k < min {
min - k
} else if k <= max {
N::zero()
} else {
k - max
}
}

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

@ogencoglu
Copy link
Author

Thanks for the swift reply.

@kylebarron
Copy link
Owner

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

@kylebarron kylebarron reopened this Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants