Matrix

Struct Matrix 

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

A Matrix with generic type items. Can be indexed by mat[(row, col)]

Implementations§

Source§

impl<T> Matrix<T>

Source

pub fn fill(rows: usize, cols: usize, e: T) -> Self
where T: Clone,

Generates a rowsxcols matrix where every element is e

Source

pub fn build<F: FnMut(usize, usize) -> T>( rows: usize, cols: usize, builder_fn: F, ) -> Self

Generates a rowsxcols matrix where every element is obtained by evaluating builder_fn(row, col)

Source

pub fn identity(rows: usize) -> Self
where T: MatrixElement,

Generates a rowsxrows identity matrix (using MatrixElement::zero() and MatrixElement::one())

Source

pub fn from_vec(rows: usize, cols: usize, data: Vec<T>) -> Option<Self>

Generates a rowsxcols matrix with the data specified in data

returns None if data.len() != rows * cols

Source§

impl<T: Clone> Matrix<&T>

Source

pub fn cloned(&self) -> Matrix<T>

Clones the elements of a Matrix<&T> and returns a Matrix<T>

Source§

impl<T> Matrix<T>

Source

pub fn rows(&self) -> usize

returns the number of rows (the ‘height’) of the matrix

Source

pub fn cols(&self) -> usize

returns the number of columns (the ‘width’) of the matrix

Source

pub fn dim(&self) -> (usize, usize)

returns the number of rows and the number of columns of the matrix (in that order)

Source

pub fn elements(&self) -> usize

returns the total number of elements in the matrix

Source

pub fn split(self) -> (usize, usize, Vec<T>)

splits the struct up into its parts, that is into (rows, columns, data)

Source

pub fn into_some(self) -> Matrix<Option<T>>

Converts a Matrix<T> to a Matrix<Option<T>> by mapping every element e to Some(e)

Source

pub fn get(&self, row: usize, col: usize) -> IndexResult<&T>

get a reference to the item at (row, col)

§Errors

Returns an error if the index is out of bounds

Source

pub fn get_mut(&mut self, row: usize, col: usize) -> IndexResult<&mut T>

get a mutable reference to the item at (row, col)

§Errors

Returns an error if the index is out of bounds

Source

pub fn replace(&mut self, row: usize, col: usize, val: T) -> IndexResult<T>

get a the item at (row, col) and replace it with val

This works like {let res = self.get(row, col); self.set(row, col, val); res} but you get ownership of the returned value

§Errors

Returns an error if the index is out of bounds

Source

pub fn set(&mut self, row: usize, col: usize, val: T) -> IndexResult<()>

set the item at (row, col) to val

§Errors

Returns an error if the index is out of bounds

Source

pub fn get_row(&self, row: usize) -> Result<Vec<&T>, IndexOutOfBounds<usize>>

get an entire row of (references of) items

§Errors

Returns an error if the row is out of bounds

Source

pub fn get_row_mut( &mut self, row: usize, ) -> Result<Vec<&mut T>, IndexOutOfBounds<usize>>

get an entire row of (mutable references of) items

§Errors

Returns an error if the row is out of bounds

Source

pub fn get_col(&self, col: usize) -> Result<Vec<&T>, IndexOutOfBounds<usize>>

get an entire column of (references of) items

§Errors

Returns an error if the column is out of bounds

Source

pub fn get_col_mut( &mut self, col: usize, ) -> Result<Vec<&mut T>, IndexOutOfBounds<usize>>

get an entire column of (mutable references of) items

§Errors

Returns an error if the column is out of bounds

Source

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

Returns a new Matrix that is obtained by applying the given function to each element

Source

pub fn transposed(self) -> Self

Returns the Transpose of this Matrix

Source

pub fn det(self) -> Option<T>
where T: Add<Output = T> + Sub<Output = T> + MatrixElement + Clone + Mul<Output = T>,

Returns the Determinant of this Matrix

Source

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

Multiplies the matrix with a scalar by multiplying each element with the scalar

Source§

impl<T> Matrix<Option<T>>

Source

pub fn take(&mut self, row: usize, col: usize) -> IndexResult<Option<T>>

return the value at (row, col), leaving None in its place

Source§

impl Matrix<RotmatElement>

Source

pub fn insert_rotation_value<T, O>(self, value: T) -> Matrix<O>
where T: Trig<Output = O> + Clone, O: Neg<Output = O> + Add<Output = O> + Mul<Output = O> + MatrixElement,

Takes a previously generated Rotation Matrix and inserts a specific value into it For f32 and f64, this would be the angle in radians, but for your own type it could be whatever… (it uses the Trig and the MatrixElement traits to get values for sin, -sin, cos, 0 and 1)

Trait Implementations§

Source§

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

Adds two matrices element by element

Source§

type Output = Matrix<O>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Clone> Clone for Matrix<T>

Source§

fn clone(&self) -> Matrix<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 Matrix<T>

Source§

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

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

impl<T: Display> Display for Matrix<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<Matrix<T>> for Vector2<T>

A Vector can be cast to a matrix and back

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<Matrix<T>> for Vector3<T>
where T: Clone,

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<Matrix<T>> for Vector4<T>
where T: Clone,

Source§

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

Converts to this type from the input type.
Source§

impl<T> Index<(usize, usize)> for Matrix<T>

Source§

type Output = T

The returned type after indexing.
Source§

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

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

impl<T> IndexMut<(usize, usize)> for Matrix<T>

Source§

fn index_mut(&mut self, (row, col): (usize, 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<Matrix<T>> for Vector2<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<Matrix<T>> for Vector3<T>

Source§

fn into(self) -> Matrix<T>

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

impl<T> Into<Matrix<T>> for Vector4<T>

Source§

fn into(self) -> Matrix<T>

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

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

Matrix Multiplication

Source§

type Output = Matrix<O>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. 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 Matrix<T>
where T: Neg<Output = O>,

Source§

type Output = Matrix<O>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Matrix<O>

Performs the unary - operation. Read more
Source§

impl<T: PartialEq> PartialEq for Matrix<T>

Source§

fn eq(&self, other: &Matrix<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: Clone + Sub<U, Output = O>, U, O> Sub<Matrix<U>> for Matrix<T>

Subtracts two matrices element by element

Source§

type Output = Matrix<O>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: Eq> Eq for Matrix<T>

Source§

impl<T> StructuralPartialEq for Matrix<T>

Auto Trait Implementations§

§

impl<T> Freeze for Matrix<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Matrix<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.