[][src]Struct spaceindex::rtree::RTree

pub struct RTree<ND> { /* fields omitted */ }

Methods

impl<ND> RTree<ND>[src]

pub fn new(dimension: usize) -> Self[src]

Creates a new RTree with the given number of dimensions.

Example

use spaceindex::rtree::RTree;

let mut tree = RTree::new(2);
tree.insert(((0.0, 0.0), (2.0, 4.0)), 1);

pub fn insert<'a, IR: IntoRegion<'a>>(
    &mut self,
    region: IR,
    data: ND
) -> Result<(), ShapelikeError>
[src]

Attempts to insert a given object into the tree.

Errors

This function will return an error if region does not have the same dimension as this tree.

Example

use spaceindex::rtree::RTree;

let mut tree = RTree::new(2);
tree.insert(((-1.0, 0.0), (3.0, 3.0)), 0);

pub fn validate_consistency(&self)[src]

Validates the consistency of the tree. In particular, this function checks that:

  • Every child is contained in the minimum bounding region of its parent, and
  • The total number of descendants of the root node is equal to the number of nodes in the tree minus one.

pub fn get_node(&self, index: Index) -> &Node<ND>[src]

Returns a reference to the Node with index index.

Panics

This function will panic if index does not refer to a node in this tree.

pub fn get_node_mut(&mut self, index: Index) -> &mut Node<ND>[src]

Returns a mutable reference to the Node with index `index.

Panics

This function will panic if index does not refer to a node in this tree.

pub fn root_node(&self) -> &Node<ND>[src]

Returns a reference to the root Node in this tree.

pub fn root_index(&self) -> Index[src]

Returns the index of the root node in this tree.

pub fn shape_lookup(&self, shape: &Shape) -> Vec<Index>[src]

Returns a Vec<Index> of those elements in the tree whose bounding box contains the minimum bounding box of the input shape.

pub fn point_lookup<IP: IntoPoint>(&self, point: IP) -> Vec<Index>[src]

Returns a Vec<Index> of those regions in the tree containing the given point point.

Example

use spaceindex::rtree::RTree;

let mut tree = RTree::new(2);

// insert a couple of regions
tree.insert(((0.0, 0.0), (2.0, 2.0)), ());
tree.insert(((1.0, 0.0), (3.0, 3.0)), ());

// Both rectangles contain the point (1.0, 1.0)
assert_eq!(tree.point_lookup((1.0, 1.0)).len(), 2);

// No rectangle should contain the point (-1.0, 0.0)
assert!(tree.point_lookup((-1.0, 0.0)).is_empty());

// Only one hit for (0.5, 0.5)
assert_eq!(tree.point_lookup((0.5, 0.5)).len(), 1);

// Two hits at (2.0, 2.0)
assert_eq!(tree.point_lookup((2.0, 2.0)).len(), 2);

// Only one hit at (2.5, 2.5)
assert_eq!(tree.point_lookup((2.5, 2.5)).len(), 1);

pub fn region_intersection_lookup<'a, IC: IntoRegion<'a>>(
    &self,
    region: IC
) -> Vec<Index>
[src]

Returns a Vec<Index> of those elements in the tree whose minimum bounding box intersects the given region.

Example

use spaceindex::rtree::RTree;

let mut tree = RTree::new(2);

// insert a couple of regions
tree.insert(((0.0, 0.0), (5.0, 5.0)), ());
tree.insert(((-1.0, 1.0), (1.0, 3.0)), ());

// Nothing should intersect with the box ((-3.0, 0.0), (-2.0, 2.0))
assert!(tree.region_intersection_lookup(((-3.0, 0.0), (-2.0, 2.0))).is_empty());

// The region ((-3.0, 0.0), (-0.5, 4.0)) should intersect the second region.
assert_eq!(tree.region_intersection_lookup(((-3.0, 0.0), (-0.5, 4.0))).len(), 1);

// The skinny box ((-2.0, 1.5), (8.0, 1.5)) should intersect both regions.
assert_eq!(tree.region_intersection_lookup(((-2.0, 1.5), (8.0, 1.5))).len(), 2);

// The region ((3.0, 2.0), (4.0, 4.0)) should only intersect the first region.
assert_eq!(tree.region_intersection_lookup(((3.0, 2.0), (4.0, 4.0))).len(), 1);

pub fn region_lookup<'a, IC: IntoRegion<'a>>(&self, region: IC) -> Vec<Index>[src]

Returns a Vec<Index> of those elements in the tree whose minimum bounding box contains the given region.

Example

use spaceindex::rtree::RTree;

let mut tree = RTree::new(2);

// insert a couple of regions
tree.insert(((0.0, 0.0), (2.0, 2.0)), ());
tree.insert(((1.0, 0.0), (3.0, 3.0)), ());

// Both regions contain the box ((1.25, 1.0), (1.75, 1.75))
assert_eq!(tree.region_lookup(((1.25, 1.0), (1.75, 1.75))).len(), 2);

// While the box ((-0.5, -0.5), (0.5, 0.5)) does intersect our first region,
// it is not contained in any region, so we should get no results.
assert!(tree.region_lookup(((-0.5, -0.5), (0.5, 0.5))).is_empty());

/// The box ((0.0, 0.5), (0.75, 1.99)) is only contained in the first region.
assert_eq!(tree.region_lookup(((0.0, 0.5), (0.75, 1.99))).len(), 1);

pub fn line_lookup(&self, line: &LineSegment) -> Vec<Index>[src]

Returns a Vec<Index> of those elements in the tree whose minimum bounding box contains the given line.

Trait Implementations

impl<ND: Debug> Debug for RTree<ND>[src]

impl<'a, ND> GraphWalk<'a> for RTree<ND>[src]

type Node = Index

type Edge = (Index, Index)

impl<'a, ND> Labeller<'a> for RTree<ND>[src]

type Node = Index

type Edge = (Index, Index)

Auto Trait Implementations

impl<ND> RefUnwindSafe for RTree<ND> where
    ND: RefUnwindSafe

impl<ND> Send for RTree<ND> where
    ND: Send

impl<ND> Sync for RTree<ND> where
    ND: Sync

impl<ND> Unpin for RTree<ND> where
    ND: Unpin

impl<ND> UnwindSafe for RTree<ND> where
    ND: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src where
    Scheme: ApproxScheme, 

type Err = NoError

The error type produced by a failed conversion.

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src where
    Dst: ApproxFrom<Src, Scheme>,
    Scheme: ApproxScheme, 

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, Dst> ConvAsUtil<Dst> for T

impl<T> ConvUtil for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SetParameter for T

impl<Src> TryFrom<Src> for Src

type Err = NoError

The error type produced by a failed conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<Src, Dst> TryInto<Dst> for Src where
    Dst: TryFrom<Src>, 

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<Src> ValueFrom<Src> for Src

type Err = NoError

The error type produced by a failed conversion.

impl<Src, Dst> ValueInto<Dst> for Src where
    Dst: ValueFrom<Src>, 

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.