pub struct GeomWithData<R: RTreeObject, T> {
    pub data: T,
    /* private fields */
}
Expand description

An RTreeObject with a geometry and some associated data that can be inserted into an r-tree.

Often, adding metadata (like a database ID) to a geometry is required before adding it into an r-tree. This struct removes some of the boilerplate required to do so.

Note: while the container itself implements RTreeObject, you will have to go through its geom method in order to access geometry-specific methods.

Example

use rstar::{RTree, PointDistance};
use rstar::primitives::GeomWithData;

type RestaurantLocation = GeomWithData<[f64; 2], &'static str>;

let mut restaurants = RTree::new();
restaurants.insert(RestaurantLocation::new([0.3, 0.2], "Pete's Pizza Place"));
restaurants.insert(RestaurantLocation::new([-0.8, 0.0], "The Great Steak"));
restaurants.insert(RestaurantLocation::new([0.2, -0.2], "Fishy Fortune"));

let my_location = [0.0, 0.0];

// Now find the closest restaurant!
let place = restaurants.nearest_neighbor(&my_location).unwrap();
println!("Let's go to {}", place.data);
println!("It's really close, only {} miles", place.distance_2(&my_location));

Fields§

§data: T

Data to be associated with the geometry being stored in the RTree.

Implementations§

source§

impl<R: RTreeObject, T> GeomWithData<R, T>

source

pub fn new(geom: R, data: T) -> Self

Create a new GeomWithData struct using the provided geometry and data.

source

pub fn geom(&self) -> &R

Get a reference to the container’s geometry.

Trait Implementations§

source§

impl<R: Clone + RTreeObject, T: Clone> Clone for GeomWithData<R, T>

source§

fn clone(&self) -> GeomWithData<R, T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<R: Debug + RTreeObject, T: Debug> Debug for GeomWithData<R, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<R: Default + RTreeObject, T: Default> Default for GeomWithData<R, T>

source§

fn default() -> GeomWithData<R, T>

Returns the “default value” for a type. Read more
source§

impl<R: Hash + RTreeObject, T: Hash> Hash for GeomWithData<R, T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<R: Ord + RTreeObject, T: Ord> Ord for GeomWithData<R, T>

source§

fn cmp(&self, other: &GeomWithData<R, T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<R: PartialEq + RTreeObject, T: PartialEq> PartialEq<GeomWithData<R, T>> for GeomWithData<R, T>

source§

fn eq(&self, other: &GeomWithData<R, T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<R: PartialOrd + RTreeObject, T: PartialOrd> PartialOrd<GeomWithData<R, T>> for GeomWithData<R, T>

source§

fn partial_cmp(&self, other: &GeomWithData<R, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<R: PointDistance, T> PointDistance for GeomWithData<R, T>

source§

fn distance_2( &self, point: &<Self::Envelope as Envelope>::Point ) -> <<Self::Envelope as Envelope>::Point as Point>::Scalar

Returns the squared euclidean distance between an object to a point.
source§

fn contains_point(&self, p: &<Self::Envelope as Envelope>::Point) -> bool

Returns true if a point is contained within this object. Read more
source§

fn distance_2_if_less_or_equal( &self, point: &<Self::Envelope as Envelope>::Point, max_distance_2: <<Self::Envelope as Envelope>::Point as Point>::Scalar ) -> Option<<<Self::Envelope as Envelope>::Point as Point>::Scalar>

Returns the squared distance to this object, or None if the distance is larger than a given maximum value. Read more
source§

impl<R: RTreeObject, T> RTreeObject for GeomWithData<R, T>

§

type Envelope = <R as RTreeObject>::Envelope

The object’s envelope type. Usually, AABB will be the right choice. This type also defines the object’s dimensionality.
source§

fn envelope(&self) -> Self::Envelope

Returns the object’s envelope. Read more
source§

impl<R: Copy + RTreeObject, T: Copy> Copy for GeomWithData<R, T>

source§

impl<R: Eq + RTreeObject, T: Eq> Eq for GeomWithData<R, T>

source§

impl<R: RTreeObject, T> StructuralEq for GeomWithData<R, T>

source§

impl<R: RTreeObject, T> StructuralPartialEq for GeomWithData<R, T>

Auto Trait Implementations§

§

impl<R, T> RefUnwindSafe for GeomWithData<R, T>where R: RefUnwindSafe, T: RefUnwindSafe,

§

impl<R, T> Send for GeomWithData<R, T>where R: Send, T: Send,

§

impl<R, T> Sync for GeomWithData<R, T>where R: Sync, T: Sync,

§

impl<R, T> Unpin for GeomWithData<R, T>where R: Unpin, T: Unpin,

§

impl<R, T> UnwindSafe for GeomWithData<R, T>where R: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.