Crates.io | quadtree_simple |
lib.rs | quadtree_simple |
version | 0.1.7 |
source | src |
created_at | 2024-05-16 04:01:37.077853 |
updated_at | 2024-05-16 08:48:51.799208 |
description | A simple quadtree implementation |
homepage | |
repository | https://github.com/zachdedoo13/quadtree-simple |
max_upload_size | |
id | 1241767 |
size | 26,667,312 |
This is a Rust library for implementing a Quadtree data structure, which is useful for efficiently storing and querying spatial data in two dimensions.
use quadtree::{Point, Qrect, Quadtree};
// Create a new quadtree with a bounding rectangle and capacity
// rects are (w, y, w, h) with x and y being anchored in the center
let size = 50.0;
let mut qt = Quadtree::new(Qrect::new(size, size, size, size), 4);
// Insert points with associated data
qt.insert(&Point::new(25., 25., 0));
qt.insert(&Point::new(30., 20., 1));
// Query points within a rectangular region
let rect = Qrect::new(20., 20., 10., 10.);
let points_in_rect = qt.query_rect(&rect);
// Query points within a circular area
let circle_points = qt.query_circle(25., 25., 5.);