Struct kd_tree::KdSliceN[][src]

pub struct KdSliceN<T, N: Unsigned>(_, _);
Expand description

A slice of kd-tree. This type implements std::ops::Deref to [T]. This is an unsized type, meaning that it must always be used as a reference. For an owned version of this type, see KdTree.

Implementations

Example

struct Item {
    point: [i32; 3],
    id: usize,
}
let mut items: Vec<Item> = vec![
    Item { point: [1, 2, 3], id: 111 },
    Item { point: [3, 1, 2], id: 222 },
    Item { point: [2, 3, 1], id: 333 },
];
let kdtree = kd_tree::KdSlice3::sort_by(&mut items, |item1, item2, k| item1.point[k].cmp(&item2.point[k]));
assert_eq!(kdtree.nearest_by(&[3, 1, 2], |item, k| item.point[k]).unwrap().item.id, 222);

Example

struct Item {
    point: [f64; 3],
    id: usize,
}
let mut items: Vec<Item> = vec![
    Item { point: [1.0, 2.0, 3.0], id: 111 },
    Item { point: [3.0, 1.0, 2.0], id: 222 },
    Item { point: [2.0, 3.0, 1.0], id: 333 },
];
use ordered_float::OrderedFloat;
let kdtree = kd_tree::KdSlice3::sort_by_key(&mut items, |item, k| OrderedFloat(item.point[k]));
assert_eq!(kdtree.nearest_by(&[3.1, 0.9, 2.1], |item, k| item.point[k]).unwrap().item.id, 222);

Example

use kd_tree::KdSlice;
let mut items: Vec<[f64; 3]> = vec![[1.0, 2.0, 3.0], [3.0, 1.0, 2.0], [2.0, 3.0, 1.0]];
let kdtree: &KdSlice<[f64; 3]> = KdSlice::sort_by_ordered_float(&mut items);
assert_eq!(kdtree.nearest(&[3.1, 0.9, 2.1]).unwrap().item, &[3.0, 1.0, 2.0]);

Example

use kd_tree::KdSlice;
let mut items: Vec<[i32; 3]> = vec![[1, 2, 3], [3, 1, 2], [2, 3, 1]];
let kdtree: &KdSlice<[i32; 3]> = KdSlice::sort(&mut items);
assert_eq!(kdtree.nearest(&[3, 1, 2]).unwrap().item, &[3, 1, 2]);

Returns the nearest item from the input point. Returns None if self.is_empty().

Example

struct Item {
    point: [f64; 3],
    id: usize,
}
let mut items: Vec<Item> = vec![
    Item { point: [1.0, 2.0, 3.0], id: 111 },
    Item { point: [3.0, 1.0, 2.0], id: 222 },
    Item { point: [2.0, 3.0, 1.0], id: 333 },
];
use ordered_float::OrderedFloat;
let kdtree = kd_tree::KdSlice3::sort_by_key(&mut items, |item, k| OrderedFloat(item.point[k]));
assert_eq!(kdtree.nearest_by(&[3.1, 0.9, 2.1], |item, k| item.point[k]).unwrap().item.id, 222);

Returns the nearest item from the input point. Returns None if self.is_empty().

Example

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

Returns the nearest item from the input point. Returns None if self.is_empty().

Example

struct Item {
    point: [f64; 3],
    id: usize,
}
let mut items: Vec<Item> = vec![
    Item { point: [1.0, 2.0, 3.0], id: 111 },
    Item { point: [3.0, 1.0, 2.0], id: 222 },
    Item { point: [2.0, 3.0, 1.0], id: 333 },
];
use ordered_float::OrderedFloat;
let kdtree = kd_tree::KdSlice3::sort_by_key(&mut items, |item, k| OrderedFloat(item.point[k]));
let nearests = kdtree.nearests_by(&[2.5, 2.0, 1.4], 2, |item, k| item.point[k]);
assert_eq!(nearests.len(), 2);
assert_eq!(nearests[0].item.id, 333);
assert_eq!(nearests[1].item.id, 222);

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::KdSlice::sort(&mut items);
let nearests = kdtree.nearests(&[3, 1, 2], 2);
assert_eq!(nearests.len(), 2);
assert_eq!(nearests[0].item, &[3, 1, 2]);
assert_eq!(nearests[1].item, &[3, 2, 2]);

search points within a rectangular region

search points within k-dimensional sphere

Trait Implementations

Performs the conversion.

Immutably borrows from an owned value. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.