Struct pathfinding::matrix::Matrix

source ·
pub struct Matrix<C> {
    pub rows: usize,
    pub columns: usize,
    /* private fields */
}
Expand description

Matrix of an arbitrary type. Data are stored consecutively in memory, by rows. Raw data can be accessed using as_ref() or as_mut().

Fields§

§rows: usize

Rows

§columns: usize

Columns

Implementations§

Create new matrix with an initial value.

Create new square matrix with initial value.

Fill with a known value.

Return a copy of a sub-matrix.

Return a copy of a matrix rotated clock-wise a number of times.

Return a copy of a matrix rotated counter-clock-wise a number of times.

Return a copy of the matrix flipped along the vertical axis.

Return a copy of the matrix flipped along the horizontal axis.

Return a copy of the matrix after transposition.

Extend the matrix in place by adding one full row.

Panics

This function panics if the row does not have the expected number of elements.

Replace a slice of the current matrix with the content of another one.

Create new matrix from vector values. The first value will be assigned to index (0, 0), the second one to index (0, 1), and so on.

Panics

This function will panic if the number of values does not correspond to the announced size.

Create new square matrix from vector values. The first value will be assigned to index (0, 0), the second one to index (0, 1), and so on.

Panics

This function will panic if the number of values is not a square number.

Create new empty matrix with a predefined number of rows. This is useful to gradually build the matrix and extend it later using extend and does not require a filler element compared to Matrix::new.

Create a matrix from something convertible to an iterator on rows, each row being convertible to an iterator on columns.

An error will be returned if length of rows differ.

use pathfinding::matrix::*;

let input = "abc\ndef";
let matrix = Matrix::from_rows(input.lines().map(|l| l.chars()))?;
assert_eq!(matrix.rows, 2);
assert_eq!(matrix.columns, 3);
assert_eq!(matrix[&(1, 1)], 'e');

Retrieve the content of the matrix as a vector. The content starts with the first row, then the second one, and so on.

Check if a matrix is a square one.

Index in raw data of a given position.

Panics

This function panics if the coordinates do not designated a cell.

Flip the matrix around the vertical axis.

Flip the matrix around the horizontal axis.

Rotate a square matrix clock-wise a number of times.

Panics

This function panics if the matrix is not square.

Rotate a square matrix counter-clock-wise a number of times.

Panics

This function panics if the matrix is not square.

Return an iterator on neighbours of a given matrix cell, with or without considering diagonals.

Trait Implementations§

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Return the number of rows.
Return the number of columns.
Return the element at position.
Return the negated weights.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.