def griditer(x, y, ncol, nrow=None, step=1):
    """
    Iterate through a grid of tiles.

    Args:
        x (int): x start-coordinate
        y (int): y start-coordinate
        ncol (int): number of tile columns
        nrow (int): number of tile rows. If not specified, this
            defaults to ncol, s.t. a quadratic region is
            generated
        step (int): clear. Analogous to range().

    Yields:
        Tuple: all tuples (x, y) in the region delimited by
            (x, y), (x + ncol, y + ncol).

    """
    if nrow is None:
        nrow = ncol
    yield from itertools.product(range(x, x + ncol, step),
                                 range(y, y + nrow, step))
Iterate through a grid of tiles.

    Args:
        x (int): x start-coordinate
        y (int): y start-coordinate
        ncol (int): number of tile columns
        nrow (int): number of tile rows. If not specified, this
            defaults to ncol, s.t. a quadratic region is
            generated
        step (int): clear. Analogous to range().

    Yields:
        Tuple: all tuples (x, y) in the region delimited by
            (x, y), (x + ncol, y + ncol).