Struct anti_r::SpatSlice[][src]

pub struct SpatSlice<'a, K, V> { /* fields omitted */ }

A slice that supports spatial queries.

The slice is basically just sorted by K. If K is a position in space this means its sorted by its coordinates which allows for spatial queries with logarithmic complexity.

If you want to modify elements just let this go out of scope, modify the base slice and rebuild the SpatSlice, potentially using new_unchecked if you uphold ordering. If you opt into the alloc feature you can also use SpatVec.

The trait bound on the K for most of the functions is PartialOrd. This is a lie. If a comparison fails the function will panic. Therefore the real trait bound would be Ord. Its just insanely inconvenient to have to deal with that for floats which are probably the mainly used data type for this.

Implementations

impl<'a, K, V> SpatSlice<'a, K, V> where
    K: PartialOrd
[src]

pub fn new(base: &'a mut [(K, V)]) -> Self[src]

Creates a new SpatSlice, by first putting base into sorted order.

pub fn new_unchecked(base: &'a [(K, V)]) -> Self[src]

When calling this instead of new you guarantee that the base is already sorted by K. An unsorted base will result in logic errors, not unsafety

pub fn query_aabb(&self, min: &K, max: &K) -> (usize, usize)[src]

Searches for all entries that are enclosed between the edges min and max. min must be smaller than max on all coordinates for this to work. If you want to query for entities enclosed by arbitrary points do an element-wise swap:

let mut min = [-1, -2,  3];
let mut max = [ 1,  2, -3];
for (min, max) in min.iter_mut().zip(&mut max) {
    if min > max {
        core::mem::swap(min, max);
    }
}
assert!(min.iter().zip(&max).all(|(min,max)| min<=max));

pub fn search_point(&self, p: &K) -> Result<usize, usize>[src]

This is literally just a binary search, as in slice.binary_search().

impl<'a, V> SpatSlice<'a, [f64; 2], V>[src]

pub fn query_distance<'c>(
    &'a self,
    center: &'c [f64; 2],
    dist2: f64
) -> impl Iterator<Item = (f64, &'a ([f64; 2], V))> + 'c where
    'a: 'c, 
[src]

Searches for all entries within a specified range around a center point.

Returns an Iterator containing (distance, &(K, V)). Excludes the point itself from the query if an exact match exists (distance will never be 0).

Dist2 is the squared distance, so if you input 100 it will search for things in range 10. If you want to search for range 100 you have to input 100*100

This is only implemented for 2d vectors, as const generics are currently unstable, and I did not want to create a Distance and scalarsub/add trait. This function is rather simple though so you can easily implement it yourself if you need a different K.

Trait Implementations

impl<'a, K: Debug, V: Debug> Debug for SpatSlice<'a, K, V>[src]

impl<'a, K, V> Deref for SpatSlice<'a, K, V>[src]

type Target = &'a [(K, V)]

The resulting type after dereferencing.

impl<'a, K, V> From<&'a SpatVec<K, V>> for SpatSlice<'a, K, V>[src]

impl<'a, K: PartialEq, V: PartialEq> PartialEq<SpatSlice<'a, K, V>> for SpatSlice<'a, K, V>[src]

impl<'a, K, V> StructuralPartialEq for SpatSlice<'a, K, V>[src]

Auto Trait Implementations

impl<'a, K, V> Send for SpatSlice<'a, K, V> where
    K: Sync,
    V: Sync
[src]

impl<'a, K, V> Sync for SpatSlice<'a, K, V> where
    K: Sync,
    V: Sync
[src]

impl<'a, K, V> Unpin for SpatSlice<'a, K, V>[src]

Blanket Implementations

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

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

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

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

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

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<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.