[][src]Struct pathfinding::grid::Grid

pub struct Grid {
    pub width: usize,
    pub height: usize,
    // some fields omitted
}

Representation of a rectangular grid in which vertices can be added or removed. Edges are automatically created between adjacent vertices. By default, only vertical and horizontal edges are created, unless diagonal mode is enabled.

Internally, a Grid is represented either as a collection of vertices or as a collection of absent vertices, depending on the density of the grid. The switch between both representations is done automatically when vertices are added or removed, or when the grid is resized.

Fields

width: usize

The grid width.

height: usize

The grid height.

Methods

impl Grid[src]

pub fn new(width: usize, height: usize) -> Grid[src]

Create a new empty grid object of the given dimensions, with diagonal mode disabled.

pub fn is_inside(&self, vertex: &(usize, usize)) -> bool[src]

Check if a (possibly removed) vertex belongs to the grid or if it is located outside the grid.

pub fn enable_diagonal_mode(&mut self)[src]

Enable diagonal mode. Diagonal edges will be created between adjacent vertices.

pub fn disable_diagonal_mode(&mut self)[src]

Disable diagonal mode. Only horizontal and vertical edges will be created between adjacent vertices.

pub fn resize(&mut self, width: usize, height: usize) -> bool[src]

Resize the grid to the given dimensions. Return true if this caused any existing vertex to be discarded.

pub fn size(&self) -> usize[src]

Return the number of positions in this grid.

pub fn vertices_len(&self) -> usize[src]

Return the number of vertices.

pub fn add_vertex(&mut self, vertex: (usize, usize)) -> bool[src]

Add a new vertex. Return true if the vertex did not previously exist and has been added.

pub fn remove_vertex(&mut self, vertex: &(usize, usize)) -> bool[src]

Remove a vertex. Return true if the vertex did previously exist and has been removed.

pub fn add_borders(&mut self) -> usize[src]

Add the borders of the grid. Return the number of added vertices.

pub fn remove_borders(&mut self) -> usize[src]

Remove the borders of the grid. Return the number of removed vertices.

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

Remove all vertices from the grid. Return true if the grid previously contained at least one vertex.

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

Fill the grid with all possible vertices. Return true if this caused the addition of at least one vertex.

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

Return true if the grid contains no vertices.

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

Return true if no additional vertices can be set (because they are all already set).

pub fn invert(&mut self)[src]

Remove every existing vertex, and add all absent vertices. If you see the grid as a black and white array, imagine that the color are exchanged.

pub fn has_vertex(&self, vertex: &(usize, usize)) -> bool[src]

Check if a vertex is present.

pub fn has_edge(&self, v1: &(usize, usize), v2: &(usize, usize)) -> bool[src]

Check if an edge is present.

Important traits for EdgesIterator<'a>
pub fn edges(&self) -> EdgesIterator[src]

Iterate over edges.

pub fn neighbours(&self, vertex: &(usize, usize)) -> Vec<(usize, usize)>[src]

Return the list of neighbours of a given vertex. If vertex is absent from the grid, an empty list is returned. Only existing vertices will be returned.

Important traits for GridIterator<'a>
pub fn iter(&self) -> GridIterator[src]

Iterate over vertices.

Trait Implementations

impl Clone for Grid[src]

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

Performs copy-assignment from source. Read more

impl IntoIterator for Grid[src]

type Item = (usize, usize)

The type of the elements being iterated over.

type IntoIter = GridIntoIterator

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a Grid[src]

type Item = (usize, usize)

The type of the elements being iterated over.

type IntoIter = GridIterator<'a>

Which kind of iterator are we turning this into?

impl FromIterator<(usize, usize)> for Grid[src]

impl Debug for Grid[src]

Auto Trait Implementations

impl Send for Grid

impl Sync for Grid

Blanket Implementations

impl<T> From for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.