georust / rstar

R*-tree spatial index for the Rust ecosystem
https://docs.rs/rstar
Apache License 2.0
386 stars 67 forks source link

Implement nearest_neighbour_mut #114

Open joverwey opened 1 year ago

joverwey commented 1 year ago

The nearest_neighbour() function returns an immutable reference to and existing node. Nodes with data associated with it, like GeomWithData<[f32;3], usize>, cannot be modified inplace. Instead one has to use pop_nearest_neighbor, change the data, and then reinsert it.

An use example case for this is an rtree that keeps visitation counts for a set of positions.

rmanoka commented 1 year ago

This is by design as we don't want the geometry to change. Try GeomWithData<G, Cell<T>> . Then you can replace the inner T as per Cell semantics (incl. replace with immutable ref. if T is copy; usize is)

grovesNL commented 2 months ago

Does locate_in_envelope_intersecting_mut have the same issue? It seems like it allows us to change the geometry, but the tree wouldn't know that the envelope haw changed.