georust/rstar

Panic after inserting `Rectangle` with NaN to `RTree`

jakoschiko opened this issue · 0 comments

I wrote a program that generates random shapes and inserts them into a RTree. I accidentally generated some shapes that contained NaN and to my surprise, the program panicked. The panic occurred inside rstar.

Here a minimal example that I've tested with rstar 0.10.0

use rstar::{RTree, primitives::Rectangle};

fn main() {
    let mut tree = RTree::new();
    tree.insert(Rectangle::from_corners([-1.4, 1.0], [-1.3, 1.1]));
    tree.insert(Rectangle::from_corners([2.3, 0.0], [2.4, 0.0]));
    tree.insert(Rectangle::from_corners([-1.4, -0.4], [-1.4, -0.2]));
    tree.insert(Rectangle::from_corners([f32::NAN, f32::NAN], [f32::NAN, f32::NAN]));
    tree.insert(Rectangle::from_corners([1.8, -1.8], [1.9, -1.8]));
    tree.insert(Rectangle::from_corners([0.2, -0.5], [0.3, -0.4]));
    tree.insert(Rectangle::from_corners([-0.6, -0.6], [-0.4, -0.5])); // This will panic!
}

Output:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/explorer/.cargo/registry/src/github.com-1ecc6299db9ec823/rstar-0.10.0/src/algorithm/rstar.rs:345:14

Rust explorer link

Is this intentional behavior?