Struct KdIndexTreeN

Source
pub struct KdIndexTreeN<'a, T, N: Unsigned> { /* private fields */ }
Expand description

This type refers a slice of items, [T], and contains kd-tree of indices to the items, KdTree<usize, N>. Unlike KdSliceN::sort, KdIndexTreeN::build doesn’t sort input items.

let items = vec![[1, 2, 3], [3, 1, 2], [2, 3, 1]];
let kdtree = kd_tree::KdIndexTree::build(&items);
assert_eq!(kdtree.nearest(&[3, 1, 2]).unwrap().item, &1); // nearest() returns an index of items.

Implementations§

Source§

impl<'a, T, N: Unsigned> KdIndexTreeN<'a, T, N>

Source

pub fn source(&self) -> &'a [T]

Source

pub fn indices(&self) -> &KdSliceN<usize, N>

Source

pub fn item(&self, i: usize) -> &'a T

Source

pub fn build_by<F>(source: &'a [T], compare: F) -> Self
where F: Fn(&T, &T, usize) -> Ordering + Copy,

Source

pub fn build_by_key<Key, F>(source: &'a [T], kd_key: F) -> Self
where Key: Ord, F: Fn(&T, usize) -> Key + Copy,

Source

pub fn build_by_ordered_float(points: &'a [T]) -> Self
where T: KdPoint<Dim = N>, T::Scalar: FloatCore,

Source

pub fn build(points: &'a [T]) -> Self
where T: KdPoint<Dim = N>, T::Scalar: Ord,

Source

pub fn nearest_by<Q: KdPoint<Dim = N>>( &self, query: &Q, coord: impl Fn(&T, usize) -> Q::Scalar + Copy, ) -> Option<ItemAndDistance<'_, usize, Q::Scalar>>

Source

pub fn nearest( &self, query: &impl KdPoint<Scalar = T::Scalar, Dim = N>, ) -> Option<ItemAndDistance<'_, usize, T::Scalar>>
where T: KdPoint<Dim = N>,

§Example
let mut items: Vec<[i32; 3]> = vec![[1, 2, 3], [3, 1, 2], [2, 3, 1]];
let kdtree = kd_tree::KdIndexTree3::build(&items);
assert_eq!(kdtree.nearest(&[3, 1, 2]).unwrap().item, &1);
Source

pub fn nearests_by<Q: KdPoint<Dim = N>>( &self, query: &Q, num: usize, coord: impl Fn(&T, usize) -> Q::Scalar + Copy, ) -> Vec<ItemAndDistance<'_, usize, Q::Scalar>>

Source

pub fn nearests( &self, query: &impl KdPoint<Scalar = T::Scalar, Dim = N>, num: usize, ) -> Vec<ItemAndDistance<'_, usize, T::Scalar>>
where T: KdPoint<Dim = N>,

Returns kNN(k nearest neighbors) from the input point.

§Example
let mut items: Vec<[i32; 3]> = vec![[1, 2, 3], [3, 1, 2], [2, 3, 1], [3, 2, 2]];
let kdtree = kd_tree::KdIndexTree::build(&mut items);
let nearests = kdtree.nearests(&[3, 1, 2], 2);
assert_eq!(nearests.len(), 2);
assert_eq!(nearests[0].item, &1);
assert_eq!(nearests[1].item, &3);
Source

pub fn within_by_cmp( &self, compare: impl Fn(&T, usize) -> Ordering + Copy, ) -> Vec<&usize>

Source

pub fn within_by<Q: KdPoint<Dim = N>>( &self, query: &[Q; 2], coord: impl Fn(&T, usize) -> Q::Scalar + Copy, ) -> Vec<&usize>

Source

pub fn within( &self, query: &[impl KdPoint<Scalar = T::Scalar, Dim = N>; 2], ) -> Vec<&usize>
where T: KdPoint<Dim = N>,

Source

pub fn within_radius_by<Q: KdPoint<Dim = N>>( &self, query: &Q, radius: Q::Scalar, coord: impl Fn(&T, usize) -> Q::Scalar + Copy, ) -> Vec<&usize>

Source

pub fn within_radius( &self, query: &impl KdPoint<Scalar = T::Scalar, Dim = N>, radius: T::Scalar, ) -> Vec<&usize>
where T: KdPoint<Dim = N>,

Trait Implementations§

Source§

impl<'a, T: Clone, N: Clone + Unsigned> Clone for KdIndexTreeN<'a, T, N>

Source§

fn clone(&self) -> KdIndexTreeN<'a, T, N>

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<'a, T: Debug, N: Debug + Unsigned> Debug for KdIndexTreeN<'a, T, N>

Source§

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

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

impl<'a, T: PartialEq, N: PartialEq + Unsigned> PartialEq for KdIndexTreeN<'a, T, N>

Source§

fn eq(&self, other: &KdIndexTreeN<'a, T, N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T: Eq, N: Eq + Unsigned> Eq for KdIndexTreeN<'a, T, N>

Source§

impl<'a, T, N: Unsigned> StructuralPartialEq for KdIndexTreeN<'a, T, N>

Auto Trait Implementations§

§

impl<'a, T, N> Freeze for KdIndexTreeN<'a, T, N>

§

impl<'a, T, N> RefUnwindSafe for KdIndexTreeN<'a, T, N>

§

impl<'a, T, N> Send for KdIndexTreeN<'a, T, N>
where T: Sync, N: Send,

§

impl<'a, T, N> Sync for KdIndexTreeN<'a, T, N>
where T: Sync, N: Sync,

§

impl<'a, T, N> Unpin for KdIndexTreeN<'a, T, N>
where N: Unpin,

§

impl<'a, T, N> UnwindSafe for KdIndexTreeN<'a, T, N>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.