Struct kd_tree::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>
impl<'a, T, N: Unsigned> KdIndexTreeN<'a, T, N>
pub fn source(&self) -> &'a [T] ⓘ
pub fn indices(&self) -> &KdSliceN<usize, N>
pub fn item(&self, i: usize) -> &'a T
pub fn build_by<F>(source: &'a [T], compare: F) -> Selfwhere
F: Fn(&T, &T, usize) -> Ordering + Copy,
pub fn build_by_key<Key, F>(source: &'a [T], kd_key: F) -> Selfwhere
Key: Ord,
F: Fn(&T, usize) -> Key + Copy,
pub fn build_by_ordered_float(points: &'a [T]) -> Selfwhere
T: KdPoint<Dim = N>,
T::Scalar: Float,
pub fn build(points: &'a [T]) -> Selfwhere
T: KdPoint<Dim = N>,
T::Scalar: Ord,
pub fn nearest_by<Q: KdPoint<Dim = N>>(
&self,
query: &Q,
coord: impl Fn(&T, usize) -> Q::Scalar + Copy
) -> Option<ItemAndDistance<'_, usize, Q::Scalar>>
sourcepub fn nearest(
&self,
query: &impl KdPoint<Scalar = T::Scalar, Dim = N>
) -> Option<ItemAndDistance<'_, usize, T::Scalar>>where
T: KdPoint<Dim = N>,
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);
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>>
sourcepub fn nearests(
&self,
query: &impl KdPoint<Scalar = T::Scalar, Dim = N>,
num: usize
) -> Vec<ItemAndDistance<'_, usize, T::Scalar>>where
T: KdPoint<Dim = N>,
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);
pub fn within_by_cmp(
&self,
compare: impl Fn(&T, usize) -> Ordering + Copy
) -> Vec<&usize>
pub fn within_by<Q: KdPoint<Dim = N>>(
&self,
query: &[Q; 2],
coord: impl Fn(&T, usize) -> Q::Scalar + Copy
) -> Vec<&usize>
pub fn within(
&self,
query: &[impl KdPoint<Scalar = T::Scalar, Dim = N>; 2]
) -> Vec<&usize>where
T: KdPoint<Dim = N>,
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>
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>
impl<'a, T: Clone, N: Clone + Unsigned> Clone for KdIndexTreeN<'a, T, N>
source§fn clone(&self) -> KdIndexTreeN<'a, T, N>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a, T: PartialEq, N: PartialEq + Unsigned> PartialEq<KdIndexTreeN<'a, T, N>> for KdIndexTreeN<'a, T, N>
impl<'a, T: PartialEq, N: PartialEq + Unsigned> PartialEq<KdIndexTreeN<'a, T, N>> for KdIndexTreeN<'a, T, N>
source§fn eq(&self, other: &KdIndexTreeN<'a, T, N>) -> bool
fn eq(&self, other: &KdIndexTreeN<'a, T, N>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.