API - pytracks.grid Module

This module helps wrap data describing a Grid. Please see the examples included to learn how to use it.

Grid

class pytracks.grid.Grid(cells)
Parameters:cells (Cell) – A list of Cell objects to seed the current Grid with.

Encapsulates a set of Cell objects with helper methods to more easily manipulate them. Other features besides the internal methods are shown below.

The Cell objects encapsulated can also be accessed by specifying an index:

>>> c1 = Cell(1, 1, [1.4, 5.3])
>>> c2 = Cell(1, 2, [1.5, 5.0])
>>> c3 = Cell(1, 3, [1.0, 4.8])
>>> g = Grid([c1, c2, c3])
>>> g[0]
<pytracks.grid.Cell object at 0x7f86b1704908>
>>> c1
<pytracks.grid.Cell object at 0x7f86b1704908>

The number of Cell objects in the current Grid can be measured by len():

>>> len(g)
3

The Grid class has the ability to iterate over every Cell object in the current Grid:

>>> for c in g:
...    print(c.point)
...
(1, 1)
(1, 2)
(1, 3)
cells

A list which composes of multiple Cell classes in the current Grid.

size

The size of the current Grid which is a tuple of form (w, h).

Cell

class pytracks.grid.Cell(x, y, data)
Parameters:
  • x (int) – The x coordinate of the cell.
  • y (int) – The y coordinate of the cell.
  • data (list) – The extra data describing the cell.

Wraps the data describing a single cell. Other features besides the internal methods are shown below.

The data encapsulated can also be accessed as if the current Cell class was the data list itself by specifying an index:

>>> c = Cell(0, 10, [1.4, 5.3])
>>> c.data[1]
5.3
>>> c[1]
5.3

The amount of data stored in the current Cell can be measured by len():

>>> len(c)
2
x

The x coordinate of the current Cell.

y

The y coordinate of the current Cell.

data

An array of the data specified to be included.

point

The coordinate of the current Cell in a tuple of form (x, y).