Struct PointCloud

Source
pub struct PointCloud<'a, T> { /* private fields */ }
Expand description

The core datastructure of the package. Stores the points and the distance function.

Implementations§

Source§

impl<'a, T> PointCloud<'a, T>

Source

pub fn new(dist_fn: fn(&T, &T) -> f64) -> Self

Constructs a new PointCloud<T>.

It accepts a function to compute distance between any 2 objects.

§Examples
extern crate knn;
use knn::PointCloud;
let manhattan_dist = |p: &[f64;2], q: &[f64;2]| -> f64 {(p[0] - q[0]).abs() + (p[1] - q[1]).abs()};
let pc = PointCloud::new(manhattan_dist);
Source

pub fn add_point(&mut self, p: &'a T)

Adds a point to the PointCloud.

It accepts a reference to an object.

§Examples
extern crate knn;
use knn::PointCloud;
let dummy_dist = |p: &[f64;2], q: &[f64;2]| -> f64 {0.0};
let mut pc = PointCloud::new(dummy_dist);
let p = [1.89, 5.63];
pc.add_point(&p);
Source

pub fn get_nearest_k(&self, p: &T, k: usize) -> Vec<(f64, &T)>

Gets the k nearest neighbours of an object.

It accepts a reference to the object and how many neighbours to return.

§Example
extern crate knn;
use knn::PointCloud;
let manhattan_dist = |p: &[f64;2], q: &[f64;2]| -> f64 {(p[0] - q[0]).abs() + (p[1] - q[1]).abs()};
let mut pc = PointCloud::new(manhattan_dist);
let points = vec![[1.0, 1.0], [2.0, 2.0], [3.0, 2.0]];
for p in &points {
    pc.add_point(&p);
}
let q = [0.5, 0.5];
pc.get_nearest_k(&q, 2);
Source

pub fn len(&self) -> usize

Get the len / number of objects in PointCloud Example:

extern crate knn;
use knn::PointCloud;
let manhattan_dist = |p: &[f64;2], q: &[f64;2]| -> f64 {(p[0] - q[0]).abs() + (p[1] - q[1]).abs()};
let mut pc = PointCloud::new(manhattan_dist);
let points = vec![[1.0, 1.0], [2.0, 2.0], [3.0, 2.0]];
for p in &points {
    pc.add_point(&p);
}
pc.len();

Trait Implementations§

Source§

impl<'a, T: Clone> Clone for PointCloud<'a, T>

Source§

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

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

Auto Trait Implementations§

§

impl<'a, T> Freeze for PointCloud<'a, T>

§

impl<'a, T> RefUnwindSafe for PointCloud<'a, T>
where T: RefUnwindSafe,

§

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

§

impl<'a, T> Sync for PointCloud<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for PointCloud<'a, T>

§

impl<'a, T> UnwindSafe for PointCloud<'a, T>
where T: RefUnwindSafe,

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