Struct kd_tree::KdTreeN[][src]

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

An owned kd-tree. This type implements std::ops::Deref to KdSlice.

Implementations

Example

struct Item {
    point: [i32; 3],
    id: usize,
}
let kdtree = kd_tree::KdTree3::build_by(
    vec![
        Item { point: [1, 2, 3], id: 111 },
        Item { point: [3, 1, 2], id: 222 },
        Item { point: [2, 3, 1], id: 333 },
    ],
    |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 kdtree = kd_tree::KdTree3::build_by_key(
    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 },
    ],
    |item, k| ordered_float::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::KdTree;
let kdtree: KdTree<[f64; 3]> = KdTree::build_by_ordered_float(vec![
    [1.0, 2.0, 3.0], [3.0, 1.0, 2.0], [2.0, 3.0, 1.0]
]);
assert_eq!(kdtree.nearest(&[3.1, 0.9, 2.1]).unwrap().item, &[3.0, 1.0, 2.0]);

Example

use kd_tree::KdTree;
let kdtree: KdTree<[i32; 3]> = KdTree::build(vec![[1, 2, 3], [3, 1, 2], [2, 3, 1]]);
assert_eq!(kdtree.nearest(&[3, 1, 2]).unwrap().item, &[3, 1, 2]);

Methods from Deref<Target = KdSliceN<T, N>>

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

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

This method tests for !=.

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

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.