Skip to content

gaudecker/spatial-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]));

About

Generic spatial data structures for Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages