Cell Coordinates

A Coord object is used to represent the x and y positions of a Cell. The x is the left position (column number) and the y is the top position (row number). The default cell coordinates is (1, 1).

This module defines the Coord tuple and give some classic use cases.

class benker.coord.Coord

Bases: benker.coord.CoordTuple

Coordinates of a cell in a grid: x is the left column, y if the top row.


>>> from benker.coord import Coord

>>> coord = Coord(5, 3)
>>> coord
Coord(x=5, y=3)
>>> coord.x
>>> coord.y
>>> str(coord)

You can use the “+” or “-” operators to move the coordinates:

>>> from benker.size import Size

>>> Coord(2, 1) + Size(3, 3)
Coord(x=5, y=4)
>>> Coord(5, 4) - Size(3, 3)
Coord(x=2, y=1)


You cannot add or subtract two coordinates, only a coordinate and a size.

>>> from benker.coord import Coord

>>> Coord(2, 1) + Coord(3, 3)
Traceback (most recent call last):
TypeError: <class 'benker.coord.Coord'>
classmethod from_value(value)

Convert a value of type tuple to a Coord tuple.

Parameters:value – tuple of two integers or Coord tuple.
Returns:Newly created object.
Raises:TypeError – if the value is not a tuple of integers nor a Coord tuple.
class benker.coord.CoordTuple(x, y)

Bases: tuple


Alias for field number 0


Alias for field number 1