Struct ameda::GridIndex
[−]
[src]
pub struct GridIndex { /* fields omitted */ }
The GridIndex
struct is used for maintaining the state of the grid.
Methods
impl GridIndex
[src]
fn new(grid_length: usize, grid_height: usize) -> Option<GridIndex>
Constructs a new 2D grid of cells that are grid_length
cells wide and grid_height
cells high. The total number of cells in the grid would be a product of both the
grid_length
and grid_height
.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 8).unwrap(); assert_eq!(grid.cell_count(), 64); let grid = GridIndex::new(5, 3).unwrap(); assert_eq!(grid.cell_count(), 15); // The minimum grid size is 2x2. The maximum is 511, 511. assert_eq!(GridIndex::new(550, 440), None); assert_eq!(GridIndex::new(1, 10), None);
fn cell_count(&self) -> usize
Returns the number of cells in the,grid
Example
use ameda::GridIndex; let grid = GridIndex::new(8, 8).unwrap(); assert_eq!(grid.cell_count(), 64);
fn row_cell_indexes(&self, row: usize) -> Option<Vec<usize>>
Returns the indices in any the rows in the grid. 0-indexed. The first row in the grid would be at the 0th index.
Example
use ameda::GridIndex; let grid = GridIndex::new(4, 4).unwrap(); assert!(grid.row_cell_indexes(1).is_some()); assert!(grid.row_cell_indexes(4).is_none()); assert_eq!(grid.row_cell_indexes(2), Some(vec![8, 9, 10, 11]));
fn col_cell_indexes(&self, column: usize) -> Option<Vec<usize>>
Returns the indices in any the columns in the grid. 0-indexed. The first column in the grid would be at the 0th index.
Example
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert!(grid.col_cell_indexes(1).is_some()); assert!(grid.col_cell_indexes(7).is_some()); assert!(grid.col_cell_indexes(8).is_none()); assert!(grid.col_cell_indexes(6).is_some());
fn top_row_indices(&self) -> &Vec<usize>
Get all the top row indices in the Grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.top_row_indices(), &vec![0, 1, 2, 3, 4, 5, 6, 7]);
fn left_column_indices(&self) -> &Vec<usize>
Get all the left row indices in the Grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.left_column_indices(), &vec![0, 8, 16, 24]);
fn right_column_indices(&self) -> &Vec<usize>
Get all the right row indices in the Grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.right_column_indices(), &vec![7, 15, 23, 31]);
fn bottom_row_indices(&self) -> &Vec<usize>
Get all the bottom row indices in the Grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.bottom_row_indices(), &vec![24, 25, 26, 27, 28, 29, 30, 31]);
fn rt_i(&self, src_index: usize) -> Option<usize>
Get the index on the "right" of the given index. Note that even though the grid may have a numerically higher index; spatially there is no "right"i index past the right most column of the grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.rt_i(6), Some(7)); assert_eq!(grid.rt_i(22), Some(23)); assert_eq!(grid.rt_i(7), None); assert_eq!(grid.rt_i(23), None);
fn dr_i(&self, src_index: usize) -> Option<usize>
Get the index on the "down-right" of the given index. Note that even though the grid may have a numerically higher index; spatially there is no "down-right" index past the right column and bottom row of the grid
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.dr_i(6), Some(15)); assert_eq!(grid.dr_i(22), Some(31)); assert_eq!(grid.dr_i(7), None); assert_eq!(grid.dr_i(25), None);
fn dn_i(&self, src_index: usize) -> Option<usize>
Get the index on the "down" of the given index. Note that even though the grid may have a numerically higher index; spatially there is no "down" index past the bottom row of the grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.dn_i(6), Some(14)); assert_eq!(grid.dn_i(22), Some(30)); assert_eq!(grid.dn_i(24), None); assert_eq!(grid.dn_i(31), None);
fn dl_i(&self, src_index: usize) -> Option<usize>
Get the index on the "down-left" of the given index. Note that even though the grid may have a numerically higher index; spatially there is no "down-left" index past the left most column and bottom row of the grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.dl_i(6), Some(13)); assert_eq!(grid.dl_i(22), Some(29)); assert_eq!(grid.dl_i(16), None); assert_eq!(grid.dl_i(26), None);
fn lt_i(&self, src_index: usize) -> Option<usize>
Get the index on the "left" of the given index. Note that even though the grid may have a numerically lower index; spatially there is no "left" index behind the left most column of the grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.lt_i(6), Some(5)); assert_eq!(grid.lt_i(22), Some(21)); assert_eq!(grid.lt_i(16), None); assert_eq!(grid.lt_i(24), None);
fn ul_i(&self, src_index: usize) -> Option<usize>
Get the index on the "upper-left" of the given index. Note that even though the grid may have a numerically lower index; spatially there is no "upper-left" index for the left most column and the top most row of the grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.ul_i(22), Some(13)); assert_eq!(grid.ul_i(17), Some(8)); assert_eq!(grid.ul_i(6), None); assert_eq!(grid.ul_i(24), None);
fn up_i(&self, src_index: usize) -> Option<usize>
Get the index on the "top" of the given index. Note that even though the grid may have a numerically lower index; spatially there is no "top" index above the top most row of the grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.up_i(22), Some(14)); assert_eq!(grid.up_i(17), Some(9)); assert_eq!(grid.up_i(6), None); assert_eq!(grid.up_i(4), None);
fn ur_i(&self, src_index: usize) -> Option<usize>
Get the index on the "top-right" of the given index. Note that even though the grid may have a numerically lower index; spatially there is no "top-right" index above the top most row or past the right most column of the grid.
Examples
use ameda::GridIndex; let grid = GridIndex::new(8, 4).unwrap(); assert_eq!(grid.ur_i(22), Some(15)); assert_eq!(grid.ur_i(17), Some(10)); assert_eq!(grid.ur_i(6), None); assert_eq!(grid.ur_i(23), None);