Vector

Struct Vector 

Source
pub struct Vector<T> { /* private fields */ }
Expand description

A Vector with generic type items. Can be indexed by vector[i]

Implementations§

Source§

impl<T> Vector<T>

Source

pub fn new(coords: Vec<T>) -> Self

Creates a new Vector with the given coordinates

Source

pub fn dim(&self) -> usize

Returns the amount of dimensions the Vector has

Source

pub fn scaled<U, O>(self, scalar: U) -> Vector<O>
where T: Mul<U, Output = O>, U: Clone,

Multiplies the vector with a scalar

Source

pub fn mag_sqr<O>(self) -> O
where T: Mul<Output = O> + Clone, O: Add<Output = O> + MatrixElement,

Returns the square of the Magnitude (also called Norm) of the Vector

Source

pub fn mag<O, U>(self) -> O
where T: Mul<Output = U> + Clone, U: Add<Output = U> + MatrixElement + SquareRootable<Output = O>,

Returns the Magnitude (also called Norm) of the Vector

Source

pub fn dot<U, O: Add<Output = O> + MatrixElement>( self, rhs: Vector<U>, ) -> Result<O, DimensionsDontMatch<usize, usize>>
where T: Mul<U, Output = O>,

Returns the Dot Product of the Vector and rhs

Source

pub fn map<F, U>(self, f: F) -> Vector<U>
where F: Fn(T) -> U,

Applies a function to every element of the vector

Trait Implementations§

Source§

impl<T: Add<U, Output = O>, U, O> Add<Vector<U>> for Vector<T>

Adds two vectors element by element

Source§

type Output = Vector<O>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector<U>) -> Vector<O>

Performs the + operation. Read more
Source§

impl<T: Clone> Clone for Vector<T>

Source§

fn clone(&self) -> Vector<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Vector<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Display> Display for Vector<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<Matrix<T>> for Vector<T>

A Vector can be converted to a matrix and back

Source§

fn from(mat: Matrix<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vector<T>> for Vector2<T>

Source§

fn from(vec: Vector<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vector<T>> for Vector3<T>

Source§

fn from(vec: Vector<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vector<T>> for Vector4<T>

Source§

fn from(vec: Vector<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for Vector<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for Vector<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for Vector<T>

Source§

fn index_mut(&mut self, i: usize) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> Into<Matrix<T>> for Vector<T>

A Vector can be cast to a matrix and back

Source§

fn into(self) -> Matrix<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T> Into<Vector<T>> for Vector2<T>

Source§

fn into(self) -> Vector<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T> Into<Vector<T>> for Vector3<T>

Source§

fn into(self) -> Vector<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T> Into<Vector<T>> for Vector4<T>

Source§

fn into(self) -> Vector<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T> IntoIterator for Vector<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, U, O> Mul<Vector<U>> for Matrix<T>
where T: Mul<U, Output = O> + Clone, U: Clone, O: Add<O, Output = O> + MatrixElement,

Matrix-Vector Multiplication

Source§

type Output = Vector<O>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector<U>) -> Vector<O>

Performs the * operation. Read more
Source§

impl<T, O> Neg for Vector<T>
where T: Neg<Output = O>,

Source§

type Output = Vector<O>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector<O>

Performs the unary - operation. Read more
Source§

impl<T: PartialEq> PartialEq for Vector<T>

Source§

fn eq(&self, other: &Vector<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, U, O> Sub<Vector<U>> for Vector<T>
where T: Sub<U, Output = O>,

Subtracts two vectors element by element

Source§

type Output = Vector<O>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector<U>) -> Vector<O>

Performs the - operation. Read more
Source§

impl<T: Eq> Eq for Vector<T>

Source§

impl<T> StructuralPartialEq for Vector<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector<T>

§

impl<T> RefUnwindSafe for Vector<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector<T>
where T: Send,

§

impl<T> Sync for Vector<T>
where T: Sync,

§

impl<T> Unpin for Vector<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector<T>
where T: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.