[][src]Struct pathfinding::matrix::Matrix

pub struct Matrix<C> {
    pub rows: usize,
    pub columns: usize,
    // some fields omitted
}

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

Methods

impl<C: Clone> Matrix<C>[src]

pub fn new(rows: usize, columns: usize, value: C) -> Matrix<C>[src]

Create new matrix with an initial value.

pub fn new_square(size: usize, value: C) -> Matrix<C>[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>) -> Matrix<C>[src]

Return a copy of a sub-matrix.

pub fn rotated_cw(&self, times: usize) -> Matrix<C>[src]

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

pub fn rotated_ccw(&self, times: usize) -> Matrix<C>[src]

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

pub fn flipped_lr(&self) -> Matrix<C>[src]

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

pub fn flipped_ud(&self) -> Matrix<C>[src]

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

pub fn transposed(&self) -> Matrix<C>[src]

Return a copy of the matrix after transposition.

pub fn extend(&mut self, row: &[C])[src]

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.

impl<C: Copy> Matrix<C>[src]

pub fn set_slice(&mut self, pos: &(usize, usize), slice: &Matrix<C>)[src]

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

impl<C> Matrix<C>[src]

pub fn from_vec(rows: usize, columns: usize, values: Vec<C>) -> Matrix<C>[src]

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.

pub fn square_from_vec(values: Vec<C>) -> Matrix<C>[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.

Panics

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

pub fn new_empty(columns: usize) -> Matrix<C>[src]

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.

pub fn from_rows<IR, IC>(rows: IR) -> Result<Matrix<C>, MatrixFormatError> where
    IR: IntoIterator<Item = IC>,
    IC: IntoIterator<Item = C>, 
[src]

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');

pub fn to_vec(self) -> Vec<C>[src]

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

pub fn is_square(&self) -> bool[src]

Check if a matrix is a square one.

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]

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

Trait Implementations

impl<C: Copy> Weights<C> for Matrix<C>[src]

impl<C: Clone> Clone for Matrix<C>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<C: Eq> Eq for Matrix<C>[src]

impl<C> AsMut<[C]> for Matrix<C>[src]

impl<C: PartialEq> PartialEq<Matrix<C>> for Matrix<C>[src]

impl<C> AsRef<[C]> for Matrix<C>[src]

impl<C: Hash> Hash for Matrix<C>[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<C: Clone + Signed> Neg for Matrix<C>[src]

type Output = Matrix<C>

The resulting type after applying the - operator.

impl<'a, C> Index<&'a (usize, usize)> for Matrix<C>[src]

type Output = C

The returned type after indexing.

impl<'a, C> IndexMut<&'a (usize, usize)> for Matrix<C>[src]

impl<C: Debug> Debug for Matrix<C>[src]

Auto Trait Implementations

impl<C> Send for Matrix<C> where
    C: Send

impl<C> Sync for Matrix<C> where
    C: Sync

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<Q, K> Equivalent for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]