2 releases
Uses old Rust 2015
0.1.1 | Feb 20, 2017 |
---|---|
0.1.0 | Feb 18, 2017 |
#14 in #neighbor
21KB
276 lines
Manipulate 2D grid indices on an unwrapped 2D grid.
While trying to implement the game of life, I noticed that a lot of logic related to manipulating the grid is not specific to "Game of Life" itself. So that part of the logic for index calculation of the grid has been abstracted into a separate library. The result is Ameda.
Amega helps to answer questions like
- What are the left/right/top/bottom most cells of a grid?
- What are the neighbors of a specific cell in the grid.
- Which cells have all 8 neighbors in the grid? (Cos some have only 3 neighbors and some only 5)
- What are the indices of the 4 corners of the grid.
Limitations
- Currently, the minimum and maximum grid size is 2x2 to 511x511 respectively.
- Higher grid sizes can be used. But 511x511 is what the library is tested with.
lib.rs
:
A 2D cell grid represented as a linear Vector. It can be used in applications that require manipulating specific sets of cells in the grid. For instance, you could get a set of the indexes of all the right most cells, left most cells, middle cells of the grid or even the neighbors of a specific cell. It is well suited for implementing different kinds of cellular automatons.
Examples
use ameda::GridIndex;
let grid = GridIndex::new(8, 8).unwrap();
assert_eq!(grid.right_column_indices(), &vec![7, 15, 23, 31, 39, 47, 55, 63]);
assert_eq!(grid.bottom_row_indices(), &vec![56, 57, 58, 59, 60, 61, 62, 63]);