hprtree

Crates.iohprtree
lib.rshprtree
version0.2.1
sourcesrc
created_at2022-09-29 15:21:50.62952
updated_at2023-04-20 19:16:35.533395
descriptionA Hilbert-Packed-R-Tree implementation for rust
homepage
repositoryhttps://github.com/Ya-hwon/hprtree
max_upload_size
id676743
size26,804
Yahwon (Ya-hwon)

documentation

README

hprtree

Crate API

About

This is a Hilbert-Packed-R-Tree implementation for rust (maybe see Wikipedia).

The (C++) code that handles the mapping between coordinates and hilbert index was not written by me and can be found on GitHub along with links to interesting writeups on (!only http) http://threadlocalmutex.com.

Example usage

use hprtree::{Point, BBox, HPRTreeBuilder};

let mut index = HPRTreeBuilder::new(10);
index.insert("Bob".to_string(), Point{ x: 0f32, y: 0f32 });
for _ in 0..2 {
    index.insert("Alice".to_string(), Point{ x: 1f32, y: 1f32 });
}
index.insert("James".to_string(), Point{ x: 2.5f32, y: -2.5f32 });
index.insert("Annie".to_string(), Point{ x: 20f32, y: 1f32 });
for _ in 0..5 {
    index.insert("Thomas".to_string(), Point{ x: 1f32, y: -50f32 });
}

let index = index.build();

let mut result = Vec::with_capacity(4);
index.query_with_list(&BBox
           {
               minx: -5f32,
               miny: -5f32,
               maxx: 5f32,
               maxy: 5f32
           }, &mut result);

assert!(result.len() == 4); // this Vec now contains the Strings "Bob", "Alice"(x2) and "James"

for i in result {
    assert!(i == "Bob".to_string() || i == "Alice".to_string() || i == "James".to_string());
    // there are absolutely no guarantees regarding ordering though
}

Also maybe see the test in lib.rs

Commit count: 13

cargo fmt