Skip to content

amphitheres/GridPy

Repository files navigation

GridPy

Overview

GridPy is a python module of procedures for indexing over arrays. A major feature is the ability to use diagonal coordinates on square grids. Full documentation is available here.

Purpose

This module is for those who need to index over a grid. Often such sequencing is useful for classic games involving a square grid such as chess or connect-four. Matrix coordinates are used often to index over square arrays. While diagonal coordinates have their uses, they are more algorithmically complex to implement. Furthermore, if you want to work with flat coordinates, matrix coordinates, and diagonal coordinates all at once you will have to write a tedious list of procedures to get the job done.

Use

Flat coordinates are regular array indices. They can be converted to matrix and diagonal coordinates.

Matrix coordinates ( i, j ) denote the i th row and j th column of the matrix. Rows are typically written left to right and rows written top to bottom.

Diagonal coordinates for square arrays map ( a, b ) to the a th diagonal and the b th element of that diagonal. Diagonal lines travel up and to the right starting at the top left corner.

flat to matrix 2d

Code Example:

flat to diagonal

Code Example:

>>> [ Grid.flat_to_diagonal(5, i) for i in range(5*5) ]
[(0, 0), (1, 0), (1, 1), (2, 0), (2, 1), (2, 2), (3, 0),
 (3, 1), (3, 2), (3, 3), (4, 0), (4, 1), (4, 2), (4, 3),
 (4, 4), (5, 0), (5, 1), (5, 2), (5, 3), (6, 0), (6, 1),
 (6, 2), (7, 0), (7, 1), (8, 0)]

Tests

This module contains tests. If you would like to activate them, run:

Future updates

Future updates to this module may include flips and rotations for matrix coordinates, and diagonal coordinates for rectangles.

About

GridPy is a module for sequencing flat arrays in different types of coordinates.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages