Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steveklabnik/spatial
Generic spatial data structures for Rust
https://github.com/steveklabnik/spatial
Last synced: 4 days ago
JSON representation
Generic spatial data structures for Rust
- Host: GitHub
- URL: https://github.com/steveklabnik/spatial
- Owner: steveklabnik
- Created: 2014-10-30T04:29:19.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-10-28T16:40:07.000Z (about 10 years ago)
- Last Synced: 2024-11-01T01:24:33.816Z (about 2 months ago)
- Size: 188 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# spatial [![Build Status](https://travis-ci.org/gaudecker/spatial.svg?branch=master)](https://travis-ci.org/gaudecker/spatial)
A library for generic spatial data structures.
## Quadtree
In order for an object to be inserted into a quadtree, the
`quadtree::Index`-trait must be implemented.```rust
extern crate spatial;
use spatial::quadtree::{Quadtree, Index, Volume};#[deriving(Clone)]
struct Object {
x: u16,
y: u16
}impl Index for Object {
fn x(&self) -> u16 {
self.x
}fn y(&self) -> u16 {
self.y
}
}
```To construct a quadtree, a bounding volume is needed.
```rust
// 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.
```rust
if tree.insert(Object { x: 68, y: 194 }) {
println!("object inserted successfully!");
}let objects = tree.get_in_volume(Volume::new((0, 0), (200, 200)));
```