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.
Methods
impl Grid
[src]
impl Grid
pub fn new(width: usize, height: usize) -> Grid
[src]
pub fn new(width: usize, height: usize) -> Grid
Create a new empty grid object of the given dimensions, with diagonal mode disabled.
pub fn is_inside(&self, vertex: &(usize, usize)) -> bool
[src]
pub fn is_inside(&self, vertex: &(usize, usize)) -> bool
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]
pub fn enable_diagonal_mode(&mut self)
Enable diagonal mode. Diagonal edges will be created between adjacent vertices.
pub fn disable_diagonal_mode(&mut self)
[src]
pub fn disable_diagonal_mode(&mut self)
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]
pub fn resize(&mut self, width: usize, height: usize) -> bool
Resize the grid to the given dimensions. Return true
if this
caused any existing vertex to be discarded.
pub fn size(&self) -> usize
[src]
pub fn size(&self) -> usize
Return the number of positions in this grid.
pub fn vertices_len(&self) -> usize
[src]
pub fn vertices_len(&self) -> usize
Return the number of vertices.
pub fn add_vertex(&mut self, vertex: (usize, usize)) -> bool
[src]
pub fn add_vertex(&mut self, vertex: (usize, usize)) -> bool
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]
pub fn remove_vertex(&mut self, vertex: &(usize, usize)) -> bool
Remove a vertex. Return true
if the vertex did previously exist
and has been removed.
pub fn add_borders(&mut self) -> usize
[src]
pub fn add_borders(&mut self) -> usize
Add the borders of the grid. Return the number of added vertices.
pub fn remove_borders(&mut self) -> usize
[src]
pub fn remove_borders(&mut self) -> usize
Remove the borders of the grid. Return the number of removed vertices.
pub fn clear(&mut self) -> bool
[src]
pub fn clear(&mut self) -> bool
Remove all vertices from the grid. Return true
if the grid
previously contained at least one vertex.
pub fn fill(&mut self) -> bool
[src]
pub fn fill(&mut self) -> bool
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]
pub fn is_empty(&self) -> bool
Return true
if the grid contains no vertices.
pub fn is_full(&self) -> bool
[src]
pub fn is_full(&self) -> bool
Return true
if no additional vertices can be set
(because they are all already set).
pub fn invert(&mut self)
[src]
pub fn invert(&mut self)
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]
pub fn has_vertex(&self, vertex: &(usize, usize)) -> bool
Check if a vertex is present.
pub fn has_edge(&self, v1: &(usize, usize), v2: &(usize, usize)) -> bool
[src]
pub fn has_edge(&self, v1: &(usize, usize), v2: &(usize, usize)) -> bool
Check if an edge is present.
ⓘImportant traits for EdgesIterator<'a>pub fn edges(&self) -> EdgesIterator
[src]
pub fn edges(&self) -> EdgesIterator
Iterate over edges.
pub fn neighbours(&self, vertex: &(usize, usize)) -> Vec<(usize, usize)>
[src]
pub fn neighbours(&self, vertex: &(usize, usize)) -> Vec<(usize, usize)>
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]
pub fn iter(&self) -> GridIterator
Iterate over vertices.
Trait Implementations
impl Clone for Grid
[src]
impl Clone for Grid
fn clone(&self) -> Grid
[src]
fn clone(&self) -> Grid
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl FromIterator<(usize, usize)> for Grid
[src]
impl FromIterator<(usize, usize)> for Grid
fn from_iter<T>(iter: T) -> Grid where
T: IntoIterator<Item = (usize, usize)>,
[src]
fn from_iter<T>(iter: T) -> Grid where
T: IntoIterator<Item = (usize, usize)>,
Creates a value from an iterator. Read more
impl IntoIterator for Grid
[src]
impl IntoIterator for Grid
type Item = (usize, usize)
The type of the elements being iterated over.
type IntoIter = GridIntoIterator
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<'a> IntoIterator for &'a Grid
[src]
impl<'a> IntoIterator for &'a Grid