Struct pathfinding::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.
Methods
impl Grid
[src]
fn new(width: usize, height: usize) -> Grid
[src]
Create a new empty grid object of the given dimensions, with diagonal mode disabled.
fn enable_diagonal_mode(&mut self)
[src]
Enable diagonal mode. Diagonal edges will be created between adjacent vertices.
fn disable_diagonal_mode(&mut self)
[src]
Disable diagonal mode. Only horizontal and vertical edges will be created between adjacent vertices.
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.
fn size(&self) -> usize
[src]
Return the number of positions in this grid.
fn vertices_len(&self) -> usize
[src]
Return the number of vertices.
fn add_vertex(&mut self, vertex: (usize, usize)) -> bool
[src]
Add a new vertex. Return true
if the vertex did not previously
exist.
fn remove_vertex(&mut self, vertex: &(usize, usize)) -> bool
[src]
Remove a vertex. Return true
if the vertex did previously exist.
fn clear(&mut self) -> bool
[src]
Remove all vertices from the grid. Return true
if the grid
previously contained at least one vertex.
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.
fn is_empty(&self) -> bool
[src]
Return true
if the grid contains no vertices.
fn is_full(&self) -> bool
[src]
Return true
if no additional vertices can be set
(because they are all already set).
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.
fn has_vertex(&self, vertex: &(usize, usize)) -> bool
[src]
Check if a vertex is present.
fn has_edge(&self, v1: &(usize, usize), v2: &(usize, usize)) -> bool
[src]
Check if an edge is present.
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.
fn iter(&self) -> GridIterator
[src]
Iterate over vertices.
Trait Implementations
impl Clone for Grid
[src]
fn clone(&self) -> Grid
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl FromIterator<(usize, usize)> for Grid
[src]
fn from_iter<T>(iter: T) -> Grid where
T: IntoIterator<Item = (usize, usize)>,
[src]
T: IntoIterator<Item = (usize, usize)>,
Creates a value from an iterator. 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?
fn into_iter(self) -> Self::IntoIter
[src]
Creates an iterator from a value. Read more