Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.06 KB

Readme.md

File metadata and controls

46 lines (33 loc) · 1.06 KB

spatial Build Status

A library for generic spatial data structures.

Documentation

Documentation can be found on rust-ci.

Quadtree

In order for an object to be inserted into a quadtree, the quadtree::Index-trait must be implemented.

extern crate spatial;
use spatial::quadtree::{Quadtree, Index, Volume};

struct Object {
    x: f32,
    y: f32
}

impl Index<f32> for Object {
    fn quadtree_index(&self) -> [f32; 2] {
        [self.x, self.y]
    }
}

To construct a quadtree, a bounding volume is needed.

// arguments are in format `[x, y], [width, height]`
let volume = Volume::new([0, 0], [640, 480]);
let mut tree = Quadtree::new(volume);

Now the quadtree is ready for insertion and querying.

if tree.insert(Object { x: 68.0, y: 194.0 }) {
    println!("object inserted successfully!");
}

let objects = tree.get_in_volume(Volume::new([0.0, 0.0], [200.0, 200.0]));