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>
impl<R: RTreeObject, T> GeomWithData<R, T>
Trait Implementations§
Source§impl<R: Clone + RTreeObject, T: Clone> Clone for GeomWithData<R, T>
impl<R: Clone + RTreeObject, T: Clone> Clone for GeomWithData<R, T>
Source§fn clone(&self) -> GeomWithData<R, T>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<R: Debug + RTreeObject, T: Debug> Debug for GeomWithData<R, T>
impl<R: Debug + RTreeObject, T: Debug> Debug for GeomWithData<R, T>
Source§impl<R: Default + RTreeObject, T: Default> Default for GeomWithData<R, T>
impl<R: Default + RTreeObject, T: Default> Default for GeomWithData<R, T>
Source§fn default() -> GeomWithData<R, T>
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>
impl<R: Hash + RTreeObject, T: Hash> Hash for GeomWithData<R, T>
Source§impl<R: Ord + RTreeObject, T: Ord> Ord for GeomWithData<R, T>
impl<R: Ord + RTreeObject, T: Ord> Ord for GeomWithData<R, T>
Source§fn cmp(&self, other: &GeomWithData<R, T>) -> Ordering
fn cmp(&self, other: &GeomWithData<R, T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<R: PartialEq + RTreeObject, T: PartialEq> PartialEq for GeomWithData<R, T>
impl<R: PartialEq + RTreeObject, T: PartialEq> PartialEq for GeomWithData<R, T>
Source§impl<R: PartialOrd + RTreeObject, T: PartialOrd> PartialOrd for GeomWithData<R, T>
impl<R: PartialOrd + RTreeObject, T: PartialOrd> PartialOrd for GeomWithData<R, T>
Source§impl<R: PointDistance, T> PointDistance for GeomWithData<R, T>
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
fn distance_2( &self, point: &<Self::Envelope as Envelope>::Point, ) -> <<Self::Envelope as Envelope>::Point as Point>::Scalar
Returns the squared distance between an object and a point. Read more
Source§fn contains_point(&self, p: &<Self::Envelope as Envelope>::Point) -> bool
fn contains_point(&self, p: &<Self::Envelope as Envelope>::Point) -> bool
Returns
true
if a point is contained within this object. Read moreSource§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>
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 moreSource§impl<R: RTreeObject, T> RTreeObject for GeomWithData<R, T>
impl<R: RTreeObject, T> RTreeObject for GeomWithData<R, T>
impl<R: Copy + RTreeObject, T: Copy> Copy for GeomWithData<R, T>
impl<R: Eq + RTreeObject, T: Eq> Eq for GeomWithData<R, T>
impl<R: RTreeObject, T> StructuralPartialEq for GeomWithData<R, T>
Auto Trait Implementations§
impl<R, T> Freeze for GeomWithData<R, T>
impl<R, T> RefUnwindSafe for GeomWithData<R, T>where
R: RefUnwindSafe,
T: RefUnwindSafe,
impl<R, T> Send for GeomWithData<R, T>
impl<R, T> Sync for GeomWithData<R, T>
impl<R, T> Unpin for GeomWithData<R, T>
impl<R, T> UnwindSafe for GeomWithData<R, T>where
R: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more