Struct multi_dim_point::Point[][src]

pub struct Point<T> { /* fields omitted */ }
Expand description

multidimensional point type.

Implementations

impl<T> Point<T> where
    T: Clone + Default
[src]

pub fn new(dimension: usize) -> Point<T>[src]

Creates a new point with default values. The size of the point base on the argument.

Examples

use multi_dim_point::Point;
let p1: Point<i32> = Point::new(3);
assert_eq!(p1.get_size(), 3);
use multi_dim_point::Point;
let p1: Point<i32> = Point::new(3);
assert_eq!(p1.get_vector(), &[0,0,0]);

impl<T> Point<T> where
    T: Clone
[src]

pub fn new_from_vec(values_vec: &Vec<T>) -> Point<T>[src]

Creates a new point from a vector.

Examples

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
assert_eq!(p1.get_vector(), &vec![1,2,3]);
use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
assert_eq!(p1.get_size(), 3);

pub fn get_vector(&self) -> &Vec<T>[src]

Return a vector with the point values.

Example

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
assert_eq!(p1.get_vector(), &vec![1,2,3]);

pub fn get_value(&self, dim_index: usize) -> &T[src]

Return a value in a specific dimension.

Examples

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,10,3]);
assert_eq!(p1.get_value(2), &10);
use multi_dim_point::Point;
let p1: Point<f32> = Point::new_from_vec(&vec![1.2, 3.2, 1.6]);
assert_eq!(p1.get_value(1), &1.2);

Panic

This function will panic when the dimension index is smaller than 1, or bigger than the point’s dimension.

use multi_dim_point::Point;
let p1: Point<f32> = Point::new_from_vec(&vec![1.2, 3.2, 1.6]);
let _ = p1.get_value(0);
use multi_dim_point::Point;
let p1: Point<f32> = Point::new_from_vec(&vec![1.2, 3.2, 1.6]);
let _ = p1.get_value(10);

pub fn set_value(&mut self, dim: usize, new_val: &T)[src]

Change the value of the point in a specific dimension.

Example

use multi_dim_point::Point;
let mut p1: Point<i32> = Point::new_from_vec(&vec![1,2]);
assert_eq!(p1.get_vector(), &vec![1,2]);
p1.set_value(1,&5);
assert_eq!(p1.get_vector(), &vec![5,2]);

Panic

This function will panic when the dimension is invalid.

use multi_dim_point::Point;
let mut p1: Point<i32> = Point::new_from_vec(&vec![1,2]);
p1.set_value(3,&3);

pub fn apply_func<S>(&self, other: &Point<T>, f: &dyn Fn(&T, &T) -> S) -> Vec<S>[src]

This function will apply a function on every pair of values in the same dimension, and return a vector of the result.

Example

use multi_dim_point::Point;

fn add_f(num1: &i32, num2: &i32) -> i32 {
    num1 + num2
}
let p1: Point<i32> = Point::new_from_vec(&vec![2, 8, 64, 256, 0]);
let p2: Point<i32> = Point::new_from_vec(&vec![2, 8, 14, 6, 0]);
assert_eq!((p1.apply_func(&p2, &add_f)), &[4, 16, 78, 262, 0])

Panic

The function will panic when the points are without equal dimensions

use multi_dim_point::Point;
fn add_f(num1: &i32, num2: &i32) -> i32 {
    num1 + num2
}
let p1: Point<i32> = Point::new_from_vec(&vec![2, 8, 64, 256, 0]);
let p2: Point<i32> = Point::new_from_vec(&vec![2, 14, 6, 0]);
p1.apply_func(&p2, &add_f);

pub fn get_size(&self) -> usize[src]

The function will return the number of dimensions of the point.

Exampl

use multi_dim_point::Point;
let p1 : Point<bool> = Point::new(3);
assert_eq!(p1.get_size(), 3);

impl<T> Point<T> where
    T: Sub<Output = T> + PartialOrd + Clone + Copy + Signed
[src]

pub fn close(&self, other: &Self, eps: T) -> bool[src]

Check if the points are close to each other, in each dimension, up to epsilon.

Examples:

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![5,10,15]);
let p2: Point<i32> = Point::new_from_vec(&vec![7,8,14]);
assert_eq!(p1.close(&p2,3), true);
use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![11,10,15]);
let p2: Point<i32> = Point::new_from_vec(&vec![7,8,14]);
assert_eq!(p1.close(&p2,3), false);
use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![7,8,14]);
let p2: Point<i32> = Point::new_from_vec(&vec![7,8,14]);
assert_eq!(p1.close(&p2,0), true);

Trait Implementations

impl<T> Add<&'_ Point<T>> for &Point<T> where
    T: Clone + Copy + Default + Add<Output = T>, 
[src]

fn add(self, other: Self) -> Point<T>[src]

+ operator. Adding values in each dimension.

Example

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
let p2: Point<i32> = Point::new_from_vec(&vec![4,5,6]);
assert_eq!((&p1+&p2).get_vector(), &vec![5,7,9]);

Panic

This function will panic if the dimensions of the points are not equal.

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
let p2: Point<i32> = Point::new_from_vec(&vec![5,6]);
&p1+&p2;

type Output = Point<T>

The resulting type after applying the + operator.

impl<T> Add<Point<T>> for Point<T> where
    T: Clone + Copy + Default + Add<Output = T>, 
[src]

fn add(self, other: Self) -> Point<T>[src]

+ operator. Adding values in each dimension.

Example

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
let p2: Point<i32> = Point::new_from_vec(&vec![4,5,6]);
assert_eq!((p1+p2).get_vector(), &vec![5,7,9]);

Panic

This function will panic if the dimensions of the points are not equal.

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
let p2: Point<i32> = Point::new_from_vec(&vec![5,6]);
p1+p2;

type Output = Point<T>

The resulting type after applying the + operator.

impl<T> Clone for Point<T> where
    T: Clone
[src]

fn clone(&self) -> Self[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T, S> Div<&'_ S> for &Point<T> where
    T: Default + Copy + Clone + Div<S, Output = T>,
    S: Copy
[src]

fn div(self, scalar: &S) -> Point<T>[src]

/ operator. Divide each value in the point.

Example

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![5,10,15]);
assert_eq!((&p1 / &5).get_vector(), &vec![1,2,3]);

type Output = Point<T>

The resulting type after applying the / operator.

impl<T, S> Div<S> for Point<T> where
    T: Default + Copy + Clone + Div<S, Output = T>,
    S: Copy
[src]

fn div(self, scalar: S) -> Point<T>[src]

/ operator. Divide each value in the point.

Example

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![5,10,15]);
assert_eq!((p1 / 5).get_vector(), &vec![1,2,3]);

type Output = Point<T>

The resulting type after applying the / operator.

impl<T, S> Mul<&'_ S> for &Point<T> where
    T: Default + Copy + Clone + Mul<S, Output = T>,
    S: Copy
[src]

fn mul(self, scalar: &S) -> Point<T>[src]

* operator. Multiply each value in the point.

Example

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
assert_eq!((&p1 * &5).get_vector(), &vec![5,10,15]);

type Output = Point<T>

The resulting type after applying the * operator.

impl<T, S> Mul<S> for Point<T> where
    T: Default + Copy + Clone + Mul<S, Output = T>,
    S: Copy
[src]

fn mul(self, scalar: S) -> Point<T>[src]

* operator. Multiply each value in the point.

Example

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
assert_eq!((p1 * 5).get_vector(), &vec![5,10,15]);

type Output = Point<T>

The resulting type after applying the * operator.

impl<T> PartialEq<Point<T>> for Point<T> where
    T: PartialEq + Clone
[src]

fn eq(&self, other: &Self) -> bool[src]

== operator. Check if 2 points are the same (in all dimensions).

Examples

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![5,10,15]);
let p2: Point<i32> = Point::new_from_vec(&vec![5,10,15]);
assert_eq!(&p1 == &p2, true);
use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![10,15]);
let p2: Point<i32> = Point::new_from_vec(&vec![5,10,15]);
assert_eq!(&p1 == &p2, false);
use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![20,10,15]);
let p2: Point<i32> = Point::new_from_vec(&vec![5,10,15]);
assert_eq!(&p1 == &p2, false);

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<T> Sub<&'_ Point<T>> for &Point<T> where
    T: Clone + Copy + Default + Sub<Output = T>, 
[src]

fn sub(self, other: Self) -> Point<T>[src]

- operator. Subtraction values in each dimension.

Example

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
let p2: Point<i32> = Point::new_from_vec(&vec![4,5,6]);
assert_eq!((&p1-&p2).get_vector(), &vec![-3,-3,-3]);

Panic

This function will panic if the dimensions of the points are not equal.

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
let p2: Point<i32> = Point::new_from_vec(&vec![5,6]);
&p1-&p2;

type Output = Point<T>

The resulting type after applying the - operator.

impl<T> Sub<Point<T>> for Point<T> where
    T: Clone + Copy + Default + Sub<Output = T>, 
[src]

fn sub(self, other: Self) -> Point<T>[src]

- operator. Subtraction values in each dimension.

Examples

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
let p2: Point<i32> = Point::new_from_vec(&vec![4,5,6]);
assert_eq!((p1-p2).get_vector(), &vec![-3,-3,-3]);

Panic

use multi_dim_point::Point;
let p1: Point<i32> = Point::new_from_vec(&vec![1,2,3]);
let p2: Point<i32> = Point::new_from_vec(&vec![5,6]);
p1-p2;

type Output = Point<T>

The resulting type after applying the - operator.

Auto Trait Implementations

impl<T> RefUnwindSafe for Point<T> where
    T: RefUnwindSafe

impl<T> Send for Point<T> where
    T: Send

impl<T> Sync for Point<T> where
    T: Sync

impl<T> Unpin for Point<T> where
    T: Unpin

impl<T> UnwindSafe for Point<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.