Commit f641f6dd authored by Nathan/Eilisha Shiraini's avatar Nathan/Eilisha Shiraini
Browse files

Docs for the positions module

parent bbf0dd98
"""
Positioning of data in the code matrix
This module contains a bunch of constants that help laying out the data
on the final code matrix. These contants are calculated at initialization time.
Attributes
----------
COMPACT_POS_MATRIX : :py:class:`list` of :py:class:`list` of :py:class:`list` of :py:class:`int`
A 3-dimentional list: dimension 1 is the number of layers - 1,
dimension 2 is the row (Y coordinate, 0 = top row),
dimension 3 is the column (X coordinate, 0 = leftmost column).
The value is the index of the bt that goes at this position in compact mode.
If the value is -1, this position is for the reference grid, the finder
or the mode message.
FULL_POS_MATRIX : :py:class:`list` of :py:class:`list` of :py:class:`list` of :py:class:`int`
A 3-dimentional list: dimension 1 is the number of layers - 1,
dimension 2 is the row (Y coordinate, 0 = top row),
dimension 3 is the column (X coordinate, 0 = leftmost column).
The value is the index of the bt that goes at this position in full mode.
If the value is -1, this position is for the reference grid, the finder
or the mode message.
COMPACT_POS_LIST : :py:class:`list` of :py:class:`list` of 2-:py:class:`tuple` of :py:class:`int`
This is the opposite of `COMPACT_POS_MATRIX`.
2-dimentional list: dimension 1 is the number of layers - 1,
dimension 2 is the index of the bit in the data stream.
The value is a 2-tuple giving the coordinates of the bit in the compact code matrix.
The first value of the tuple is the row (Y coordinate, 0 = top row),
the second value is the column (X coordinate, 0 = leftmost column)
FULL_POS_LIST : :py:class:`list` of :py:class:`list` of 2-:py:class:`tuple` of :py:class:`int`
This is the opposite of `FULL_POS_MATRIX`.
2-dimentional list: dimension 1 is the number of layers - 1,
dimension 2 is the index of the bit in the data stream.
The value is a 2-tuple giving the coordinates of the bit in the full code matrix.
The first value of the tuple is the row (Y coordinate, 0 = top row),
the second value is the column (X coordinate, 0 = leftmost column)
"""
def matrixSize(layers, compact):
"""
Calcuates the size (number of modules of one side) of the code
Parameters
----------
layers : :py:class:`int`
The number of layers used for arrangement
compact : :py:class:`bool`
:py:const:`True` if compact arrangement is used, :py:const:`False` otherwise.
Returns
-------
:py:class:`int`
The number of modules on one side of the code
"""
if compact:
return 11 + layers * 4
else:
return 15 + layers * 4 + 2 * (((14 + layers * 4) // 2 - 1) // 15)
def positionMatrix(layers, compact):
def _positionMatrix(layers, compact):
size = matrixSize(layers, compact)
if compact:
baseSize = 11 + layers * 4
......@@ -33,9 +86,9 @@ def positionMatrix(layers, compact):
rowOffset += rowSize * 8
return matrix
def positionList(layers, compact):
def _positionList(layers, compact):
size = matrixSize(layers, compact)
matrix = positionMatrix(layers, compact)
matrix = _positionMatrix(layers, compact)
lst = [(-1, -1)] * (size * size)
for i, row in enumerate(matrix):
for j, cell in enumerate(row):
......@@ -44,7 +97,7 @@ def positionList(layers, compact):
del lst[lst.index((-1, -1)):]
return lst
COMPACT_POS_MATRIX = [positionMatrix(i, True) for i in range(1, 5)]
FULL_POS_MATRIX = [positionMatrix(i, False) for i in range(1, 33)]
COMPACT_POS_LIST = [positionList(i, True) for i in range(1, 5)]
FULL_POS_LIST = [positionList(i, False) for i in range(1, 33)]
COMPACT_POS_MATRIX = [_positionMatrix(i, True) for i in range(1, 5)]
FULL_POS_MATRIX = [_positionMatrix(i, False) for i in range(1, 33)]
COMPACT_POS_LIST = [_positionList(i, True) for i in range(1, 5)]
FULL_POS_LIST = [_positionList(i, False) for i in range(1, 33)]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment