quad3

Crates.ioquad3
lib.rsquad3
version0.1.0
sourcesrc
created_at2023-03-05 13:41:07.553683
updated_at2023-03-05 13:41:07.553683
descriptionA simple quadtree implementation in Rust
homepage
repositoryhttps://github.com/DimitriTimoz/quadtree
max_upload_size
id801378
size10,553
DimitriTimoz (DimitriTimoz)

documentation

README

Quad3

Crates.io Docs.rs

A quadtree implementation in rust.

Usage

Add this to your Cargo.toml:

[dependencies]
quad3 = "0.1"

Example

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);
Commit count: 9

cargo fmt