We can associate points, lines, or rectangles with a custom data. We use GeomWithData to define new types that contain our custom data.
type PointWithName = GeomWithData<(i32, i32), String>;The example defines a new type PointWithName that associates a point with a String.
Then we can use this type to construct objects that can be searched later.
The complete code is presented below:
use rstar::{primitives::GeomWithData, RTree};
fn main() {
type PointWithName = GeomWithData<(i32, i32), String>;
let p1 = PointWithName::new((0, 0), "A".into());
let p2 = PointWithName::new((2, 1), "B".into());
let tree = RTree::bulk_load(vec![p1, p2]);
println!("{:?}", tree.nearest_neighbors(&(2, 2)));
}Output:
[GeomWithData { geom: (2, 1), data: "B" }]
➡️ Next: Shooting Elements
📘 Back: Table of contents