kiddo icon indicating copy to clipboard operation
kiddo copied to clipboard

`nearest_n_within` does not limit the number of items when not sorted

Open Nahor opened this issue 9 months ago • 8 comments

In kiddo v4.2.0, nearest_n_within will only limit the number of items if sorting is enabled. If it's disabled, all the items within the radius are returned.

E.g. in the cities example, replace nearest_n with nearest_n_within and a radius of 10km.

-let nearest_5_idx = kdtree.nearest_n::<SquaredEuclidean>(&query, 5);
+let nearest_5_idx = kdtree.nearest_n_within::<SquaredEuclidean>(
+     &query,
+     kilometres_to_unit_sphere_squared_euclidean(10.0),
+    5,
+    false,
+);

This outputs 13 cities (for my data set) instead of the expected 5. If the list is sorted, then it works as expected.


Also note that the example in the documentation for nearest_n_within creates a tree of 2 items, asks for 2 items, and then is happy because it got 2 items in return!

Nahor avatar May 08 '24 06:05 Nahor