kdtree-rs
kdtree-rs copied to clipboard
Is it possible to have a function nearest_radius that includes the maximum radius?
I think that everything is ready to allow users to pass the maximum radius when searching for nearest points. Unfortunately rust does not support optional arguments yet, so something like this could be trivial to implement:
pub fn nearest_radius<F>(
&self,
point: &[A],
num: usize,
radius: A,
distance: &F,
)
The current function
pub fn nearest<F>(
&self,
point: &[A],
num: usize,
distance: &F,
)
calls to
self.nearest_step(
point,
num,
A::infinity(),
distance,
&mut pending,
&mut evaluated,
);
which already has the maximum radius as A::infinity().
So we already have nearest
by count and within
by radius, and the suggestion seems to be a combination of them.
Any thoughts how we can combine them with a flexible interface instead of adding another method?
Currently not actively working on this - if you're interested, a PR would be great!
If it is possible to modify the function signature (adding the new parameter) the modified function should be:
pub fn nearest<F>(
&self,
point: &[A],
num: usize,
radius: A,
distance: &F,
)
Not sure if a good idea to change the API. That was the reason to propose a new method instead. A simple solution could be implementing a new nearest_with_radius and the old nearest calls to nearest_with_radius to avoid code duplication:
pub fn nearest<F>(
&self,
point: &[A],
num: usize,
radius: A,
distance: &F,
) -> Result<Vec<(A, &T)>, ErrorKind> {
nearest_with_radius(self,point,num, A::infinity(), distance)
}
I can make PR but I want to discuss first with you the proposed solution.
Thanks @exepulveda I'm supportive of merging them into one interface - it'd be a breaking change & we will just follow semantic versioning bumping to 0.7
Closing stale issue. Please re-open as needed.