# [−][src]Trait cgmath::Matrix

    pub trait Matrix: VectorSpace where
        Self::Scalar: BaseFloat,
        Self: Index<usize, Output = Self::Column>,
        Self: IndexMut<usize, Output = Self::Column>,
        Self: AbsDiffEq<Epsilon = Self::Scalar>,
        Self: RelativeEq<Epsilon = Self::Scalar>,
        Self: UlpsEq<Epsilon = Self::Scalar>, {
        type Row: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>;
        type Column: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>;
        type Transpose: Matrix<Scalar = Self::Scalar, Row = Self::Column, Column = Self::Row>;
        fn row(&self, r: usize) -> Self::Row;
        fn swap_rows(&mut self, a: usize, b: usize);
        fn swap_columns(&mut self, a: usize, b: usize);
        fn swap_elements(&mut self, a: (usize, usize), b: (usize, usize));
        fn transpose(&self) -> Self::Transpose;

        fn as_ptr(&self) -> *const Self::Scalar { ... }
        fn as_mut_ptr(&mut self) -> *mut Self::Scalar { ... }
        fn replace_col(&mut self, c: usize, src: Self::Column) -> Self::Column { ... }
    }

A column-major matrix of arbitrary dimensions.

Because this is constrained to the `VectorSpace` trait, this means that following operators are required to be implemented:

Matrix addition:

- `Add<Output = Self>`
- `Sub<Output = Self>`
- `Neg<Output = Self>`

Scalar multiplication:

- `Mul<Self::Scalar, Output = Self>`
- `Div<Self::Scalar, Output = Self>`
- `Rem<Self::Scalar, Output = Self>`

Note that matrix multiplication is not required for implementors of this trait. This is due to the complexities of implementing these operators with Rust's current type system. For the multiplication of square matrices, see `SquareMatrix`.

## Associated Types

### `type Row: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>`

The row vector of the matrix.

### `type Column: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>`

The column vector of the matrix.

### `type Transpose: Matrix<Scalar = Self::Scalar, Row = Self::Column, Column = Self::Row>`

The result of transposing the matrix

Loading content...

## Required methods

### `fn row(&self, r: usize) -> Self::Row`

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) -> Self::Transpose`

Transpose this matrix, returning a new matrix.

Loading content...

## Provided methods

### `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.

Loading content...

## Implementors

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

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

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

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

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

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

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

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

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

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

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

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

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

#### `fn row(&self, r: usize) -> Vector3<S>`[src]

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

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

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

#### `fn transpose(&self) -> Matrix3<S>`[src]

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

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

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

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

#### `fn row(&self, r: usize) -> Vector4<S>`[src]

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

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

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

#### `fn transpose(&self) -> Matrix4<S>`[src]

Loading content...

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)