Struct pathfinding::matrix::Matrix [−][src]
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
impl<C: Clone> Matrix<C>
[src]
impl<C: Clone> Matrix<C>
[src]pub fn new(rows: usize, columns: usize, value: C) -> Self
[src]
Create new matrix with an initial value.
pub fn new_square(size: usize, value: C) -> Self
[src]
Create new square matrix with initial value.
pub fn fill(&mut self, value: C)
[src]
Fill with a known value.
pub fn slice(
&self,
rows: Range<usize>,
columns: Range<usize>
) -> Result<Self, MatrixFormatError>
[src]
&self,
rows: Range<usize>,
columns: Range<usize>
) -> Result<Self, MatrixFormatError>
Return a copy of a sub-matrix, or return an error if the ranges are outside the original matrix.
#[must_use]pub fn rotated_cw(&self, times: usize) -> Self
[src]
Return a copy of a matrix rotated clock-wise a number of times.
#[must_use]pub fn rotated_ccw(&self, times: usize) -> Self
[src]
Return a copy of a matrix rotated counter-clock-wise a number of times.
#[must_use]pub fn flipped_lr(&self) -> Self
[src]
Return a copy of the matrix flipped along the vertical axis.
#[must_use]pub fn flipped_ud(&self) -> Self
[src]
Return a copy of the matrix flipped along the horizontal axis.
#[must_use]pub fn transposed(&self) -> Self
[src]
Return a copy of the matrix after transposition.
pub fn extend(&mut self, row: &[C]) -> Result<(), MatrixFormatError>
[src]
Extend the matrix in place by adding one full row. An error is returned if the row does not have the expected number of elements.
impl<C: Copy> Matrix<C>
[src]
impl<C: Copy> Matrix<C>
[src]impl<C> Matrix<C>
[src]
impl<C> Matrix<C>
[src]pub fn from_vec(
rows: usize,
columns: usize,
values: Vec<C>
) -> Result<Self, MatrixFormatError>
[src]
rows: usize,
columns: usize,
values: Vec<C>
) -> Result<Self, MatrixFormatError>
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. An error is returned instead if data length does not correspond to the announced size.
pub fn square_from_vec(values: Vec<C>) -> Result<Self, MatrixFormatError>
[src]
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. An error is returned if the number of values is not a square number.
#[must_use]pub fn new_empty(columns: usize) -> Self
[src]
Create new empty matrix with a predefined number of columns.
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
.
pub fn from_rows<IR, IC>(rows: IR) -> Result<Self, MatrixFormatError> where
IR: IntoIterator<Item = IC>,
IC: IntoIterator<Item = C>,
[src]
IR: IntoIterator<Item = IC>,
IC: IntoIterator<Item = C>,
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');
#[must_use]pub fn is_square(&self) -> bool
[src]
Check if a matrix is a square one.
#[must_use]pub fn idx(&self, i: &(usize, usize)) -> usize
[src]
Index in raw data of a given position.
Panics
This function panics if the coordinates do not designated a cell.
pub fn flip_lr(&mut self)
[src]
Flip the matrix around the vertical axis.
pub fn flip_ud(&mut self)
[src]
Flip the matrix around the horizontal axis.
pub fn rotate_cw(&mut self, times: usize)
[src]
Rotate a square matrix clock-wise a number of times.
Panics
This function panics if the matrix is not square.
pub fn rotate_ccw(&mut self, times: usize)
[src]
Rotate a square matrix counter-clock-wise a number of times.
Panics
This function panics if the matrix is not square.
pub fn neighbours(
&self,
index: &(usize, usize),
diagonals: bool
) -> impl Iterator<Item = (usize, usize)>
[src]
&self,
index: &(usize, usize),
diagonals: bool
) -> impl Iterator<Item = (usize, usize)>
Return an iterator on neighbours of a given matrix cell, with or without considering diagonals.
pub fn in_direction(
&self,
index: &(usize, usize),
direction: (isize, isize)
) -> impl Iterator<Item = (usize, usize)>
[src]
&self,
index: &(usize, usize),
direction: (isize, isize)
) -> impl Iterator<Item = (usize, usize)>
Return an iterator of cells in a given direction starting from a given cell. Any direction (including with values greater than 1) can be given. The starting cell is not included in the results.
Examples
Starting from square (1, 1)
in a 8×8 chessboard, move like a knight
by steps of two rows down and one column right:
let m = Matrix::new_square(8, '.'); assert_eq!(m.in_direction(&(1, 1), (2, 1)).collect(), vec![(3, 2), (5, 3), (7, 4)]);
Starting from square (3, 2)
in the same chessboard, move diagonally in
the North-West direction:
let m = Matrix::new_square(8, '.'); assert_eq!(m.in_direction(&(3, 2), directions::NW).collect(), vec![(2, 1), (1, 0)]);
#[must_use]pub fn iter(&self) -> RowIterator<'_, C>ⓘNotable traits for RowIterator<'a, C>
impl<'a, C> Iterator for RowIterator<'a, C> type Item = &'a [C];
[src]
Notable traits for RowIterator<'a, C>
impl<'a, C> Iterator for RowIterator<'a, C> type Item = &'a [C];
Return an iterator on rows of the matrix.
pub fn indices(&self) -> impl Iterator<Item = (usize, usize)>
[src]
Return an iterator on the Matrix indices, first row first.
#[must_use]pub fn values(&self) -> Iter<'_, C>
[src]
Return an iterator on values, first row first.
#[must_use]pub fn values_mut(&mut self) -> IterMut<'_, C>
[src]
Return a mutable iterator on values, first row first.
Trait Implementations
impl<'a, C> IntoIterator for &'a Matrix<C>
[src]
impl<'a, C> IntoIterator for &'a Matrix<C>
[src]type IntoIter = RowIterator<'a, C>
Which kind of iterator are we turning this into?
type Item = &'a [C]
The type of the elements being iterated over.
#[must_use]fn into_iter(self) -> RowIterator<'a, C>ⓘNotable traits for RowIterator<'a, C>
impl<'a, C> Iterator for RowIterator<'a, C> type Item = &'a [C];
[src]
Notable traits for RowIterator<'a, C>
impl<'a, C> Iterator for RowIterator<'a, C> type Item = &'a [C];
impl<C: Eq> Eq for Matrix<C>
[src]
impl<C> StructuralEq for Matrix<C>
[src]
impl<C> StructuralPartialEq for Matrix<C>
[src]
Auto Trait Implementations
impl<C> RefUnwindSafe for Matrix<C> where
C: RefUnwindSafe,
C: RefUnwindSafe,
impl<C> Send for Matrix<C> where
C: Send,
C: Send,
impl<C> Sync for Matrix<C> where
C: Sync,
C: Sync,
impl<C> Unpin for Matrix<C> where
C: Unpin,
C: Unpin,
impl<C> UnwindSafe for Matrix<C> where
C: UnwindSafe,
C: UnwindSafe,