Trait spade::HasPosition
source · Expand description
An object that has a position.
Describes a point like object that has a well defined position.
Since this trait also implements SpatialObject
, HasPosition
can serve as a quick and
easy implementation of your own pointlike objects that can be inserted into r-trees
or delaunay triangulations:
extern crate cgmath;
extern crate spade;
use cgmath::Point3;
use spade::HasPosition;
use spade::rtree::RTree;
struct MyPoint {
position: Point3<f32>,
my_data: i32,
}
impl HasPosition for MyPoint {
type Point = Point3<f32>;
fn position(&self) -> Point3<f32> {
self.position
}
}
fn main() {
let mut tree = RTree::new();
tree.insert(MyPoint { position: Point3::new(0.0, 1.0, 0.0), my_data: 42 });
assert_eq!(tree.lookup(&Point3::new(0.0, 1.0, 0.0)).unwrap().my_data, 42);
}