#quad-tree #spatial #tree #graphics #algorithm

quadtree_rs

Point/region Quadtree with support for overlapping regions

3 releases

0.1.3 Jun 13, 2023
0.1.2 Apr 6, 2019
0.1.1 Apr 6, 2019

#438 in Visualization

Download history 9/week @ 2023-12-23 3/week @ 2023-12-30 7/week @ 2024-01-06 12/week @ 2024-01-13 7/week @ 2024-01-20 7/week @ 2024-01-27 5/week @ 2024-02-03 55/week @ 2024-02-10 575/week @ 2024-02-17 332/week @ 2024-02-24 308/week @ 2024-03-02 305/week @ 2024-03-09 268/week @ 2024-03-16 228/week @ 2024-03-23 333/week @ 2024-03-30 229/week @ 2024-04-06

1,109 downloads per month
Used in 2 crates

Apache-2.0

62KB
939 lines

quadtree_rs

crates.io badge docs.rs badge license

Point/region Quadtree with support for overlapping regions.

For documentation, see docs.rs/quadtree_rs.

Quick Start

use quadtree_rs::{area::AreaBuilder, point::Point, Quadtree};

// Instantiate a new quadtree which associates String values with u64 
// coordinates.
let mut qt = Quadtree::<u64, String>::new(/*depth=*/4);

// A depth of four means a square with width (and height) 2^4.
assert_eq!(qt.width(), 16);

// Associate the value "foo" with a rectangle of size 2x1, anchored at (0, 0).
let region_a = AreaBuilder::default()
    .anchor(Point {x: 0, y: 0})
    .dimensions((2, 1))
    .build().unwrap();
qt.insert(region_a, "foo".to_string());

// Query over a region of size 2x2, anchored at (1, 0).
let region_b = AreaBuilder::default()
    .anchor(Point {x: 1, y: 0})
    .dimensions((2, 2))
    .build().unwrap();
let mut query = qt.query(region_b);

// The query region (region_b) intersects the region "foo" is associated with 
// (region_a), so the query iterator returns "foo" by reference.
assert_eq!(query.next().unwrap().value_ref(), "foo");

Questions?

Please file an issue on GitHub.

Authors

See Cargo.toml.

Contributing

See CONTRIBUTING.md and NOTES.md

License

This project is licensed under the Apache 2.0 license.

Disclaimer

This is not an official Google product.

TODO

  • Pretty-print quadtree function which plots a density map
  • Benchmark tests

Dependencies

~3MB
~66K SLoC