kdtree-rs icon indicating copy to clipboard operation
kdtree-rs copied to clipboard

Is it possible to have a function nearest_radius that includes the maximum radius?

Open exepulveda opened this issue 4 years ago • 3 comments

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().

exepulveda avatar Aug 19 '20 11:08 exepulveda

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!

mrhooray avatar Aug 20 '20 01:08 mrhooray

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.

exepulveda avatar Aug 20 '20 11:08 exepulveda

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

mrhooray avatar Aug 20 '20 19:08 mrhooray

Closing stale issue. Please re-open as needed.

mrhooray avatar Dec 16 '22 08:12 mrhooray