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]
impl<T> Point<T> where
T: Clone + Default,
[src]pub fn new(dimension: usize) -> Point<T>
[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]
impl<T> Point<T> where
T: Clone,
[src]pub fn new_from_vec(values_vec: &Vec<T>) -> Point<T>
[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]
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]
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]
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]
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);
impl<T> Point<T> where
T: Sub<Output = T> + PartialOrd + Clone + Copy + Signed,
[src]
impl<T> Point<T> where
T: Sub<Output = T> + PartialOrd + Clone + Copy + Signed,
[src]pub fn close(&self, other: &Self, eps: T) -> bool
[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]
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]
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;
impl<T> Add<Point<T>> for Point<T> where
T: Clone + Copy + Default + Add<Output = T>,
[src]
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]
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;
impl<T, S> Div<&'_ S> for &Point<T> where
T: Default + Copy + Clone + Div<S, Output = T>,
S: Copy,
[src]
impl<T, S> Div<&'_ S> for &Point<T> where
T: Default + Copy + Clone + Div<S, Output = T>,
S: Copy,
[src]impl<T, S> Mul<&'_ S> for &Point<T> where
T: Default + Copy + Clone + Mul<S, Output = T>,
S: Copy,
[src]
impl<T, S> Mul<&'_ S> for &Point<T> where
T: Default + Copy + Clone + Mul<S, Output = T>,
S: Copy,
[src]impl<T, S> Mul<S> for Point<T> where
T: Default + Copy + Clone + Mul<S, Output = T>,
S: Copy,
[src]
impl<T, S> Mul<S> for Point<T> where
T: Default + Copy + Clone + Mul<S, Output = T>,
S: Copy,
[src]impl<T> PartialEq<Point<T>> for Point<T> where
T: PartialEq + Clone,
[src]
impl<T> PartialEq<Point<T>> for Point<T> where
T: PartialEq + Clone,
[src]fn eq(&self, other: &Self) -> bool
[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);
impl<T> Sub<&'_ Point<T>> for &Point<T> where
T: Clone + Copy + Default + Sub<Output = T>,
[src]
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]
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;
impl<T> Sub<Point<T>> for Point<T> where
T: Clone + Copy + Default + Sub<Output = T>,
[src]
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]
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;
Auto Trait Implementations
impl<T> RefUnwindSafe for Point<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Point<T> where
T: Send,
T: Send,
impl<T> Sync for Point<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Point<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Point<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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