Struct grid::Grid [] [src]

pub struct Grid { /* fields omitted */ }

Methods

impl Grid
[src]

[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");

[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);

[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");

[src]

Returns tile character. When specified coordinates are out of grid bound None is returned.

[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).

[src]

[src]

[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");

[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);

[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]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Display for Grid
[src]

[src]

Formats the value using the given formatter. Read more