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

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.

Implementations

impl Grid[src]

#[must_use]
pub fn new(width: usize, height: usize) -> Self
[src]

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

#[must_use]
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.

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

Return the number of positions in this grid.

#[must_use]
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.

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

Return true if the grid contains no vertices.

#[must_use]
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.

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

Check if a vertex is present.

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

Check if an edge is present.

#[must_use]
pub fn edges(&self) -> EdgesIterator<'_>

Notable traits for EdgesIterator<'a>

impl<'a> Iterator for EdgesIterator<'a> type Item = ((usize, usize), (usize, usize));
[src]

Iterate over edges.

#[must_use]
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.

#[must_use]
pub fn iter(&self) -> GridIterator<'_>

Notable traits for GridIterator<'a>

impl<'a> Iterator for GridIterator<'a> type Item = (usize, usize);
[src]

Iterate over vertices.

#[must_use]
pub fn distance(&self, a: &(usize, usize), b: &(usize, usize)) -> usize
[src]

Distance between two potential vertices. If diagonal mode is enabled, this is the maximum of both coordinates difference. If diagonal mode is disabled, this is the Manhattan distance.

Trait Implementations

impl Clone for Grid[src]

impl Debug for Grid[src]

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

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?

Auto Trait Implementations

impl RefUnwindSafe for Grid

impl Send for Grid

impl Sync for Grid

impl Unpin for Grid

impl UnwindSafe for Grid

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.