geo-index
geo-index copied to clipboard
`RTreeBuilder` panics on `.finish()` if given capacity is 1
If you create an RTreeBuilder with capacity 1, insert 1 element, and then attempt to .finish() to produce an OwnedRTree, it will panic with the following message:
thread 'main' panicked at /home/kade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/geo-index-0.1.1/src/rtree/builder.rs:129:13:
index out of bounds: the len is 4 but the index is 4
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
A minimal reproduction is here: https://github.com/kade-robertson/geo-index-repro
use geo_index::rtree::{sort::HilbertSort, RTreeBuilder};
fn main() {
let mut builder: RTreeBuilder<f64> = RTreeBuilder::new(1);
builder.add(-20., -20., 1020., 1020.);
builder.finish::<HilbertSort>();
}
I realize an r-tree with only 1 bbox is.. somewhat pointless, so I'm not necessarily expecting this to work, but there should maybe be a note or an additional assert inside new_with_node_size.
Yeah... I've hit this same bug before, but fixed it for my own use case by avoiding length-1 trees. I believe the upstream JS implementation also suffers from the same behavior.
I think it would be nice to handle length-1 indexes for symmetry. A PR would be accepted either to improve the error message or to handle length-1 indexes properly