Struct Matrix2x2

Source
pub struct Matrix2x2 {
    pub r1: Vector2,
    pub r2: Vector2,
}
Expand description

Implements a matrix 2 x 2

Fields§

§r1: Vector2§r2: Vector2

Implementations§

Source§

impl Matrix2x2

Source

pub fn IDENTITY() -> Self

Identity Matrrix NxN, where all elements Uij that i = j are 1

// | 1 0 |
// | 0 1 |
Source

pub fn det(&self) -> f32

Matrix determinant

//                | 4 -3 |
// let matrix =   | 0  2 |

// matrix.det() = 2
use mathf::matrix::{Matrix2x2};

let matrix = Matrix2x2::new_idx(4.0, -3.0, 0.0, 2.0);
assert_eq!(matrix.det(), 8f32);
Source

pub fn vectorize(&self) -> Vec<Vec<f32>>

Transforms a MatrixNxN into a Vec<Vec> by row

//                | 4 -3 |`
// let matrix =   | 0  2 |`
// matrix.det() = 2
use mathf::matrix::{Matrix2x2};

let matrix = Matrix2x2::new_idx(4.0, -3.0, 0.0, 2.0);
assert_eq!(matrix.vectorize(), vec![
   vec![4.0, -3.0], vec![0.0, 2.0]    
]);
Source

pub fn modulus(&self) -> f32

Same as determinant for Matrix 2x2

Source

pub fn transpose(&self) -> Self

Transpose of Matrix NxN. Transpose switches rows and columns

Source

pub fn inverse(&self, delta: f32) -> Result<Matrix2x2, Error>

Matrix inverse

//                | 4 7 |
// let matrix =   | 2 6 |
//
//                             |  6 -7 |
// let matrix_inverse =  1/10  | -2  4 |
use mathf::matrix::{Matrix2x2};

let matrix = Matrix2x2::new_idx(4.0, 7.0, 2.0, 6.0);
let matrix_inverse = Matrix2x2::new_idx(0.6, -0.7, -0.2, 0.4);
assert_eq!(matrix.inverse(0.001).unwrap(), matrix_inverse);
Source

pub fn is_orthogonal(&self) -> bool

A matrix is orthogonal if and only if transpose(A) == inverse(A)

Source

pub fn scale_matrix(a: f32) -> Self

// | a 0 |
// | 0 a |
Source

pub fn new(r1: Vector2, r2: Vector2) -> Matrix2x2

Creates a new Matrix2x2 from 2 vector2 rows

Source

pub fn new_idx(n1: f32, n2: f32, n3: f32, n4: f32) -> Matrix2x2

Creates a new Matrix2x2 from 4 indexed floats

Source

pub fn scale_matrix_non_uniform(a: f32, b: f32) -> Self

Source

pub fn rotation_2d(teta: f32) -> Self

2D rotation Matrix by angle teta (radians) For matrix 2x2:

// P′= | cosθ − sinθ | P
//     | sinθ + cosθ |

Trait Implementations§

Source§

impl Add for &Matrix2x2

Source§

fn add(self, new: &Matrix2x2) -> Matrix2x2

Implements the &Matrix 2x2 ‘+’ trait

Source§

type Output = Matrix2x2

The resulting type after applying the + operator.
Source§

impl Add for Matrix2x2

Source§

fn add(self, new: Matrix2x2) -> Matrix2x2

Implements the Matrix 2x2 ‘+’ trait

Source§

type Output = Matrix2x2

The resulting type after applying the + operator.
Source§

impl Clone for Matrix2x2

Source§

fn clone(&self) -> Matrix2x2

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 Debug for Matrix2x2

Source§

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

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

impl Div<f32> for &Matrix2x2

Source§

fn div(self, value: f32) -> Matrix2x2

Implements the Matrix 2x2 ‘/’ trait for &Matrix2x2 / f32 so that (identity / value).det() == valueˆ2.

Source§

type Output = Matrix2x2

The resulting type after applying the / operator.
Source§

impl Div<f32> for Matrix2x2

Source§

fn div(self, value: f32) -> Matrix2x2

Implements the Matrix 2x2 ‘/’ trait for Matrix2x2 / f32 so that (identity / value).det() == valueˆ2.

Source§

type Output = Matrix2x2

The resulting type after applying the / operator.
Source§

impl Index<usize> for Matrix2x2

Source§

type Output = Vector2

The returned type after indexing.
Source§

fn index(&self, s: usize) -> &Vector2

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

impl Mul<&Matrix2x2> for f32

Source§

fn mul(self, m: &Matrix2x2) -> Matrix2x2

Implements the &Matrix 2x2 ‘*’ trait for &Matrix2x2 * f32 so that (value * identity).det() == valueˆ2 and ßM == Mߘ.

Source§

type Output = Matrix2x2

The resulting type after applying the * operator.
Source§

impl Mul<&Point2> for &Matrix2x2

Source§

fn mul(self, vec: &Point2) -> Point2

Implements the transform matrix of a point 2 into another point 2. The order should be matrix * point because of 2x2 * 2x1 = 2x1

Source§

type Output = Point2

The resulting type after applying the * operator.
Source§

impl Mul<&Point2> for Matrix2x2

Source§

fn mul(self, vec: &Point2) -> Point2

Implements the transform matrix of a vector 2 into another vector 2. The order should be matrix * &point because of 2x2 * 2x1 = 2x1

Source§

type Output = Point2

The resulting type after applying the * operator.
Source§

impl Mul<&Vector2> for &Matrix2x2

Source§

fn mul(self, vec: &Vector2) -> Vector2

Implements the transform matrix of a vector 2 into another vector 2. The order should be matrix * vector because of 2x2 * 2x1 = 2x1

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

impl Mul<&Vector2> for Matrix2x2

Source§

fn mul(self, vec: &Vector2) -> Vector2

Implements the transform matrix of a vector 2 into another vector 2. The order should be matrix * &vector because of 2x2 * 2x1 = 2x1

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

impl Mul<Matrix2x2> for f32

Source§

fn mul(self, m: Matrix2x2) -> Matrix2x2

Implements the Matrix 2x2 ‘*’ trait for Matrix2x2 * f32 so that (value * identity).det() == valueˆ2 and ßM == Mߘ.

Source§

type Output = Matrix2x2

The resulting type after applying the * operator.
Source§

impl Mul<Vector2> for Matrix2x2

Source§

fn mul(self, vec: Vector2) -> Vector2

Implements the transform matrix of a vector 2 into another vector 2. The order should be matrix * vector because of 2x2 * 2x1 = 2x1

Source§

type Output = Vector2

The resulting type after applying the * operator.
Source§

impl Mul<f32> for &Matrix2x2

Source§

fn mul(self, value: f32) -> Matrix2x2

Implements the &Matrix 2x2 ‘*’ trait for &Matrix2x2 * f32 so that (identity * value).det() == valueˆ2.

Source§

type Output = Matrix2x2

The resulting type after applying the * operator.
Source§

impl Mul<f32> for Matrix2x2

Source§

fn mul(self, value: f32) -> Matrix2x2

Implements the Matrix 2x2 ‘*’ trait for Matrix2x2 * f32 so that (identity * value).det() == valueˆ2.

Source§

type Output = Matrix2x2

The resulting type after applying the * operator.
Source§

impl Mul for Matrix2x2

Source§

fn mul(self, m: Matrix2x2) -> Matrix2x2

Implements the Matrix 2x2 ‘*’ trait for Matrix2x2 * Matrix2x2

Source§

type Output = Matrix2x2

The resulting type after applying the * operator.
Source§

impl PartialEq for Matrix2x2

Source§

fn eq(&self, other: &Matrix2x2) -> 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 StructuralPartialEq for Matrix2x2

Auto Trait Implementations§

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.