Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 1.45 KB

shooting_elements.md

File metadata and controls

36 lines (24 loc) · 1.45 KB

Shooting Elements

We can find elements that are located at a given point or containing that point. This can be done by using locate_at_point.

In the following example, we find the rectangle that contains the point (1.5, 1.5).

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

fn main() {
    let rect1 = Rectangle::from_corners((0., 0.), (1., 1.));
    let rect2 = Rectangle::from_corners((1., 1.), (2., 2.));
    let rect3 = Rectangle::from_corners((2., 2.), (3., 3.));

    let tree = RTree::bulk_load(vec![rect1, rect2, rect3]);

    println!("{:?}", tree.locate_at_point(&(1.5, 1.5)));
}

Output:

Some(Rectangle { aabb: AABB { lower: (1.0, 1.0), upper: (2.0, 2.0) } })

There are variants of locate_at_point:

➡️ Next: Rectangle Queries

📘 Back: Table of contents