Struct spade::rtree::RTree

source ·
pub struct RTree<T>where
    T: SpatialObject,
{ /* private fields */ }
Expand description

A rust implementation of n dimensional r*-trees

R-trees provide efficient nearest-neighbor searches for many objects. R*-trees ("R-Star-Trees") are a common variant of r-trees and use more advanced heuristics to improve query performance. Instead of linear time complexity, r-trees yield logarithmic complexity for look-up operations and nearest neighbor queries. Inserting into an r-tree runs in O(log(n)) time on average. Also, a bulk loading algorithm is implemented for faster and higher quality tree creation. Some simple geometric primitives that can be inserted into an r-tree can be found in the primitives module. If your object is not among those, consider implementing the SpatialObject trait.


use nalgebra::{Point4};
use spade::rtree::RTree;

  let mut tree = RTree::new();
  tree.insert(Point4::new(13i32, 10, 10, 37));

Basic Example

extern crate cgmath; // Alternatively: use nalgebra or [f32; 2]
extern crate spade;

use spade::rtree::RTree;
use cgmath::Point2;

fn main() {
let mut rtree = RTree::new();
// Insert two points
rtree.insert(Point2::new(0.5, 0.5f32));
rtree.insert(Point2::new(1.0, 1.0f32));

if rtree.lookup(&Point2::new(0.5, 0.5)).is_some() {
  println!("Found point at [0.5, 0.5]/");
}
 
let nearest = rtree.nearest_neighbor(&Point2::new(1.5, 1.5)).unwrap();
println!("nearest neighbor at [1.5, 1.5]: {:?}", nearest);

// Iterate over all elements
for point in rtree.iter() {
  println!("Found point: {:?}", point);
}
}

Implementations

Creates an empty r*-tree.

Returns the trees minimal bounding box.

Returns the number of elements contained in this r-tree.

Returns an iterator over all contained elements.

Returns the nearest neighbor.

Returns None if the tree is empty.

Returns an object close to a given point. This operation is faster than nearest_neighbor but will not neccessarily yield the real nearest neighbor.

Returns the nearest neighbors of a given point.

All returned values will have the exact same distance from the given query point. Returns an empty Vec if the tree is empty.

Returns the nearest n neighbors.

Returns an iterator over the nearest neighbors of a point.

Returns all objects (partially) contained in a rectangle

Returns all objects (partially) contained in a circle.

Note that radius2 is the circle’s squared radius, not the actual radius. An object is contained if a part of it lies within the circle.

Creates a new rtree with some initial elements.

This method should run faster than inserting all elements sequentially. Also, the resulting rtree should have better quality in terms of query performance. This is an implementation of the OMT algorithm.

The current implementation only works for two dimensional data.

Searches for an element at a given position.

If query_point is contained by one object in the tree, this object will be returned. If multiple objects contain the point, only one of them will be returned.

Searches for an element at a given position and returns a mutable reference. If query_point is contained by multiple objects in the tree, one of them will be returned. Do not change the object’s minimal bounding box.

Inserts a new element into the tree.

This will require O(log(n)) operations on average, where n is the number of elements contained in the tree.

Searches for an element and removes it.

If the given point is contained by one object in the tree, this object is being removed and returned. If the point is contained by multiple objects, only one of them is removed and returned.

Removes an object from the tree.

Locates and removes an object from the tree, returning true if the element could be removed. If multiple object’s are equal to to_remove, only one will be deleted.

Returns true if a given object is contained in this tree.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
source

fn insert_vertex_entry(&mut self, entry: VertexEntry<T>)

This method is called when a new vertex entry has been inserted.
source

fn update_vertex_entry(&mut self, new_entry: VertexEntry<T>)

This method is called when a vertex has been updated.
source

fn remove_vertex_entry(&mut self, to_remove: &VertexEntry<T>)

This method is callend when a vertex has been removed.
Returns, if possible, a vertex handle that is close to the given point.
Notifies the locate structure about the result of a query.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.