# Struct cgmath::Matrix2 [−] [src]

```pub struct Matrix2<S> {
pub x: Vector2<S>,
pub y: Vector2<S>,
}```

A 2 x 2, column major matrix

This type is marked as `#[repr(C, packed)]`.

## Fields

`x: Vector2<S>`

The first column of the matrix.

`y: Vector2<S>`

The second column of the matrix.

## Methods

### `impl<S: BaseFloat> Matrix2<S>`[src]

#### `fn new(c0r0: S, c0r1: S, c1r0: S, c1r1: S) -> Matrix2<S>`

Create a new matrix, providing values for each index.

#### `fn from_cols(c0: Vector2<S>, c1: Vector2<S>) -> Matrix2<S>`

Create a new matrix, providing columns.

#### `fn look_at(dir: Vector2<S>, up: Vector2<S>) -> Matrix2<S>`

Create a transformation matrix that will cause a vector to point at `dir`, using `up` for orientation.

## Trait Implementations

### `impl<S: PartialEq> PartialEq for Matrix2<S>`[src]

#### `fn eq(&self, __arg_0: &Matrix2<S>) -> bool`

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `fn ne(&self, __arg_0: &Matrix2<S>) -> bool`

This method tests for `!=`.

### `impl<S: Clone> Clone for Matrix2<S>`[src]

#### `fn clone(&self) -> Matrix2<S>`

Returns a copy of the value. Read more

#### `fn clone_from(&mut self, source: &Self)`1.0.0

Performs copy-assignment from `source`. Read more

### `impl<S: BaseFloat> Zero for Matrix2<S>`[src]

#### `fn zero() -> Matrix2<S>`

Returns the additive identity element of `Self`, `0`. Read more

#### `fn is_zero(&self) -> bool`

Returns `true` if `self` is equal to the additive identity.

### `impl<S: BaseFloat> One for Matrix2<S>`[src]

#### `fn one() -> Matrix2<S>`

Returns the multiplicative identity element of `Self`, `1`. Read more

### `impl<S: BaseFloat> VectorSpace for Matrix2<S>`[src]

#### `type Scalar = S`

The associated scalar.

### `impl<S: BaseFloat> Matrix for Matrix2<S>`[src]

#### `type Column = Vector2<S>`

The column vector of the matrix.

#### `type Row = Vector2<S>`

The row vector of the matrix.

#### `type Transpose = Matrix2<S>`

The result of transposing the matrix

#### `fn row(&self, r: usize) -> Vector2<S>`

Get a row from this matrix by-value.

#### `fn swap_rows(&mut self, a: usize, b: usize)`

Swap two rows of this array.

#### `fn swap_columns(&mut self, a: usize, b: usize)`

Swap two columns of this array.

#### `fn swap_elements(&mut self, a: (usize, usize), b: (usize, usize))`

Swap the values at index `a` and `b`

#### `fn transpose(&self) -> Matrix2<S>`

Transpose this matrix, returning a new matrix.

#### `fn as_ptr(&self) -> *const Self::Scalar`

Get the pointer to the first element of the array.

#### `fn as_mut_ptr(&mut self) -> *mut Self::Scalar`

Get a mutable pointer to the first element of the array.

#### `fn replace_col(&mut self, c: usize, src: Self::Column) -> Self::Column`

Replace a column in the array.

### `impl<S: BaseFloat> SquareMatrix for Matrix2<S>`[src]

#### `type ColumnRow = Vector2<S>`

The row/column vector of the matrix. Read more

#### `fn from_value(value: S) -> Matrix2<S>`

Create a new diagonal matrix using the supplied value.

#### `fn from_diagonal(value: Vector2<S>) -> Matrix2<S>`

Create a matrix from a non-uniform scale

#### `fn transpose_self(&mut self)`

Transpose this matrix in-place.

#### `fn determinant(&self) -> S`

Take the determinant of this matrix.

#### `fn diagonal(&self) -> Vector2<S>`

Return a vector containing the diagonal of this matrix.

#### `fn invert(&self) -> Option<Matrix2<S>>`

Invert this matrix, returning a new matrix. `m.mul_m(m.invert())` is the identity matrix. Returns `None` if this matrix is not invertible (has a determinant of zero). Read more

#### `fn is_diagonal(&self) -> bool`

Test if this is a diagonal matrix. That is, every element outside of the diagonal is 0. Read more

#### `fn is_symmetric(&self) -> bool`

Test if this matrix is symmetric. That is, it is equal to its transpose. Read more

#### `fn identity() -> Self`

The [identity matrix]. Multiplying this matrix with another should have no effect. Read more

#### `fn trace(&self) -> Self::Scalar`

Return the trace of this matrix. That is, the sum of the diagonal.

#### `fn is_invertible(&self) -> bool`

Test if this matrix is invertible.

#### `fn is_identity(&self) -> bool`

Test if this matrix is the identity matrix. That is, it is diagonal and every element in the diagonal is one. Read more

### `impl<S: BaseFloat> Neg for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `-` operator

#### `fn neg(self) -> Matrix2<S>`

The method for the unary `-` operator

### `impl<'a, S: BaseFloat> Neg for &'a Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `-` operator

#### `fn neg(self) -> Matrix2<S>`

The method for the unary `-` operator

### `impl<S: BaseFloat> Mul<S> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: S) -> Matrix2<S>`

The method for the `*` operator

### `impl<'a, S: BaseFloat> Mul<S> for &'a Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: S) -> Matrix2<S>`

The method for the `*` operator

### `impl<S: BaseFloat> Div<S> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `/` operator

#### `fn div(self, other: S) -> Matrix2<S>`

The method for the `/` operator

### `impl<'a, S: BaseFloat> Div<S> for &'a Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `/` operator

#### `fn div(self, other: S) -> Matrix2<S>`

The method for the `/` operator

### `impl<S: BaseFloat> Rem<S> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `%` operator

#### `fn rem(self, other: S) -> Matrix2<S>`

The method for the `%` operator

### `impl<'a, S: BaseFloat> Rem<S> for &'a Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `%` operator

#### `fn rem(self, other: S) -> Matrix2<S>`

The method for the `%` operator

### `impl<S: BaseFloat + MulAssign<S>> MulAssign<S> for Matrix2<S>`[src]

#### `fn mul_assign(&mut self, scalar: S)`

The method for the `*=` operator

### `impl<S: BaseFloat + DivAssign<S>> DivAssign<S> for Matrix2<S>`[src]

#### `fn div_assign(&mut self, scalar: S)`

The method for the `/=` operator

### `impl<S: BaseFloat + RemAssign<S>> RemAssign<S> for Matrix2<S>`[src]

#### `fn rem_assign(&mut self, scalar: S)`

The method for the `%=` operator

### `impl<S: BaseFloat> Add<Matrix2<S>> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `+` operator

#### `fn add(self, other: Matrix2<S>) -> Matrix2<S>`

The method for the `+` operator

### `impl<'a, S: BaseFloat> Add<&'a Matrix2<S>> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `+` operator

#### `fn add(self, other: &'a Matrix2<S>) -> Matrix2<S>`

The method for the `+` operator

### `impl<'a, S: BaseFloat> Add<Matrix2<S>> for &'a Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `+` operator

#### `fn add(self, other: Matrix2<S>) -> Matrix2<S>`

The method for the `+` operator

### `impl<'a, 'b, S: BaseFloat> Add<&'a Matrix2<S>> for &'b Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `+` operator

#### `fn add(self, other: &'a Matrix2<S>) -> Matrix2<S>`

The method for the `+` operator

### `impl<S: BaseFloat> Sub<Matrix2<S>> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `-` operator

#### `fn sub(self, other: Matrix2<S>) -> Matrix2<S>`

The method for the `-` operator

### `impl<'a, S: BaseFloat> Sub<&'a Matrix2<S>> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `-` operator

#### `fn sub(self, other: &'a Matrix2<S>) -> Matrix2<S>`

The method for the `-` operator

### `impl<'a, S: BaseFloat> Sub<Matrix2<S>> for &'a Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `-` operator

#### `fn sub(self, other: Matrix2<S>) -> Matrix2<S>`

The method for the `-` operator

### `impl<'a, 'b, S: BaseFloat> Sub<&'a Matrix2<S>> for &'b Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `-` operator

#### `fn sub(self, other: &'a Matrix2<S>) -> Matrix2<S>`

The method for the `-` operator

### `impl<S: BaseFloat + AddAssign<S>> AddAssign<Matrix2<S>> for Matrix2<S>`[src]

#### `fn add_assign(&mut self, other: Matrix2<S>)`

The method for the `+=` operator

### `impl<S: BaseFloat + SubAssign<S>> SubAssign<Matrix2<S>> for Matrix2<S>`[src]

#### `fn sub_assign(&mut self, other: Matrix2<S>)`

The method for the `-=` operator

### `impl<S: BaseFloat> Mul<Vector2<S>> for Matrix2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: Vector2<S>) -> Vector2<S>`

The method for the `*` operator

### `impl<'a, S: BaseFloat> Mul<&'a Vector2<S>> for Matrix2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: &'a Vector2<S>) -> Vector2<S>`

The method for the `*` operator

### `impl<'a, S: BaseFloat> Mul<Vector2<S>> for &'a Matrix2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: Vector2<S>) -> Vector2<S>`

The method for the `*` operator

### `impl<'a, 'b, S: BaseFloat> Mul<&'a Vector2<S>> for &'b Matrix2<S>`[src]

#### `type Output = Vector2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: &'a Vector2<S>) -> Vector2<S>`

The method for the `*` operator

### `impl<S: BaseFloat> Mul<Matrix2<S>> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: Matrix2<S>) -> Matrix2<S>`

The method for the `*` operator

### `impl<'a, S: BaseFloat> Mul<&'a Matrix2<S>> for Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: &'a Matrix2<S>) -> Matrix2<S>`

The method for the `*` operator

### `impl<'a, S: BaseFloat> Mul<Matrix2<S>> for &'a Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: Matrix2<S>) -> Matrix2<S>`

The method for the `*` operator

### `impl<'a, 'b, S: BaseFloat> Mul<&'a Matrix2<S>> for &'b Matrix2<S>`[src]

#### `type Output = Matrix2<S>`

The resulting type after applying the `*` operator

#### `fn mul(self, other: &'a Matrix2<S>) -> Matrix2<S>`

The method for the `*` operator

### `impl<S> Index<usize> for Matrix2<S>`[src]

#### `type Output = Vector2<S>`

The returned type after indexing

#### `fn index<'a>(&'a self, i: usize) -> &'a Vector2<S>`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> IndexMut<usize> for Matrix2<S>`[src]

#### `fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vector2<S>`

The method for the indexing (`Foo[Bar]`) operation

### `impl<S> Into<[[S; 2]; 2]> for Matrix2<S>`[src]

#### `fn into(self) -> [[S; 2]; 2]`

Performs the conversion.

### `impl<S> AsRef<[[S; 2]; 2]> for Matrix2<S>`[src]

#### `fn as_ref(&self) -> &[[S; 2]; 2]`

Performs the conversion.

### `impl<S> AsMut<[[S; 2]; 2]> for Matrix2<S>`[src]

#### `fn as_mut(&mut self) -> &mut [[S; 2]; 2]`

Performs the conversion.

### `impl<S: Copy> From<[[S; 2]; 2]> for Matrix2<S>`[src]

#### `fn from(m: [[S; 2]; 2]) -> Matrix2<S>`

Performs the conversion.

### `impl<'a, S> From<&'a [[S; 2]; 2]> for &'a Matrix2<S>`[src]

#### `fn from(m: &'a [[S; 2]; 2]) -> &'a Matrix2<S>`

Performs the conversion.

### `impl<'a, S> From<&'a mut [[S; 2]; 2]> for &'a mut Matrix2<S>`[src]

#### `fn from(m: &'a mut [[S; 2]; 2]) -> &'a mut Matrix2<S>`

Performs the conversion.

### `impl<S> AsRef<[S; 4]> for Matrix2<S>`[src]

#### `fn as_ref(&self) -> &[S; 4]`

Performs the conversion.

### `impl<S> AsMut<[S; 4]> for Matrix2<S>`[src]

#### `fn as_mut(&mut self) -> &mut [S; 4]`

Performs the conversion.

### `impl<'a, S> From<&'a [S; 4]> for &'a Matrix2<S>`[src]

#### `fn from(m: &'a [S; 4]) -> &'a Matrix2<S>`

Performs the conversion.

### `impl<'a, S> From<&'a mut [S; 4]> for &'a mut Matrix2<S>`[src]

#### `fn from(m: &'a mut [S; 4]) -> &'a mut Matrix2<S>`

Performs the conversion.

### `impl<S: Debug> Debug for Matrix2<S>`[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result`

Formats the value using the given formatter.

### `impl<S: BaseFloat + Rand> Rand for Matrix2<S>`[src]

#### `fn rand<R: Rng>(rng: &mut R) -> Matrix2<S>`

Generates a random instance of this type using the specified source of randomness. Read more

### `impl<S: BaseFloat> From<Basis2<S>> for Matrix2<S>`[src]

#### `fn from(b: Basis2<S>) -> Matrix2<S>`

Performs the conversion.