Crates.io | quad3 |
lib.rs | quad3 |
version | 0.1.0 |
source | src |
created_at | 2023-03-05 13:41:07.553683 |
updated_at | 2023-03-05 13:41:07.553683 |
description | A simple quadtree implementation in Rust |
homepage | |
repository | https://github.com/DimitriTimoz/quadtree |
max_upload_size | |
id | 801378 |
size | 10,553 |
A quadtree implementation in rust.
Add this to your Cargo.toml
:
[dependencies]
quad3 = "0.1"
use quad3::prelude::*;
// Create a new quadtree with a bounding box of 20x20 centred in (0, 0) and a max amount of 4 items per node
let mut quadtree = QuadTree::new(Box2d::new(Point::new(0.0, 0.0), 10.0), 4);
assert!(quadtree.insert(&Point::new(0.0, 0.0)));
assert!(quadtree.insert(&Point::new(0.5, 0.5)));
assert!(quadtree.insert(&Point::new(-0.5, -0.5)));
assert!(quadtree.insert(&Point::new(1.5, 1.5)));
assert!(quadtree.insert(&Point::new(-1.5, -1.5)));
assert!(quadtree.insert(&Point::new(2.5, 2.5)));
assert!(quadtree.insert(&Point::new(-2.5, -2.5)));
// Query a range of 2x2 centred in (0, 0)
let points = quadtree.query_range(Box2d::new(Point::new(0.0, 0.0), 1.0));
assert_eq!(points.len(), 3);