Struct pathfinding::grid::Grid [−][src]
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]
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<'_>ⓘ
[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]
Notable traits for GridIterator<'a>
impl<'a> Iterator for GridIterator<'a> type Item = (usize, usize);
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 IntoIterator for Grid
[src]
impl IntoIterator for Grid
[src]