Struct grid::Grid
[−]
[src]
pub struct Grid { /* fields omitted */ }
Methods
impl Grid
[src]
fn filled_with(width: usize, height: usize, fill: char) -> Self
[src]
Creates new grid filled with specified character
Examples
use grid::Grid; let grid = Grid::filled_with(2,2,'x'); assert_eq!(&grid.to_string(), "xx\nxx\n");
fn new(width: usize, height: usize) -> Self
[src]
Creates new grid of defined dimensions.
Examples
use grid::Grid; let grid = Grid::new(2,3); assert_eq!(grid.width(), 2); assert_eq!(grid.height(), 3);
fn from(tiles: &str) -> Self
[src]
Creates grid from string.
Examples
use grid::Grid; let grid = Grid::from("#*#\n| |\n+-+"); assert_eq!(grid.width(), 3); assert_eq!(grid.to_string(), "#*#\n| |\n+-+\n");
fn get(&self, x: usize, y: usize) -> Option<char>
[src]
Returns tile character. When specified coordinates are out of grid bound None is returned.
fn set(&mut self, x: usize, y: usize, new_tile: char) -> bool
[src]
Sets tile character on specified coordinates. Returns true if character was set. Returns false when tile was not set (specified coordinates were out of grid bounds).
fn width(&self) -> usize
[src]
fn height(&self) -> usize
[src]
fn fill(&mut self, start_x: usize, start_y: usize, fill: char)
[src]
Fills grid with given character. Works like a flood fill replacing all neighbour tile's characters which are differend than specified fill character.
Examples
use grid::Grid; // ######## // #......# // #.####.# // #.####.# // #......# // ######## let mut grid = Grid::from("########\n#......#\n#.####.#\n#.####.#\n#......#\n########"); grid.fill(2,2,'.'); // ######## // #......# // #......# // #......# // #......# // ######## assert_eq!(&grid.to_string(),"########\n#......#\n#......#\n#......#\n#......#\n########\n");
use grid::Grid; // #..# // #### let mut grid = Grid::from("#..#\n####"); grid.fill(1,0,'+'); assert_eq!(grid.to_string(), "++++\n++++\n");
fn count(&self, tile: char) -> usize
[src]
Counts tiles with specified character.
Examples
use grid::Grid; let grid = Grid::from("#.\n##"); assert_eq!(grid.count('.'), 1); assert_eq!(grid.count('#'), 3);
fn neighbours(&self, x: usize, y: usize) -> Vec<(usize, usize)>
[src]
Returns coordinates of neighbour tiles (including diagonal).
Examples
use grid::Grid; let grid = Grid::new(10,10); assert_eq!(grid.neighbours(5,5), vec![(5, 4), (6, 5), (5, 6), (4, 5), (6, 6), (6, 4), (4, 4), (4, 6)]); assert_eq!(grid.neighbours(0,0), vec![(1, 0), (0, 1), (1, 1)]); assert_eq!(grid.neighbours(9,9), vec![(9, 8), (8, 9), (8, 8)]); assert_eq!(grid.neighbours(100,100), vec![]); assert_eq!(grid.neighbours(0,100), vec![]); assert_eq!(grid.neighbours(100,0), vec![]);
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