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

Return distances from KDTree::within function #119

Open
adamthedash opened this issue Jan 13, 2025 · 1 comment
Open

Return distances from KDTree::within function #119

adamthedash opened this issue Jan 13, 2025 · 1 comment

Comments

@adamthedash
Copy link

Hi, thanks for creating this crate!
For my use case (swarm simulation), I'm searching for nearby entities using KDTree::within. However as it only returns the indices, I'm re-calculating the distances of neighbours to use downstream. I see internally that KDTree::within is already calculating it for candidate points, so was wondering if they could also be returned alongside the indices?

@kylebarron
Copy link
Owner

Hello 👋

That sounds like you probably ideally want to use nearest neighbors instead of within. This is tracked by #97.

The RTree implementation already has the nearest neighbor implementation, but an improvement will be to expose it as a rust Iterator instead of collecting into a Vec, see #98 for a WIP but not yet functional implementation.

In this case, the item yielded by the iterator includes both the id and the (squared) distance:

id: usize,
dist: N,

I think this approach would work the best for you as well: to implement an iterator-based nearest-neighbor search and then you can stop iteration once you've hit a certain number or distance.

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