def square_rect_deindex(index, rect_x, rect_y, width, height):
    """Performs the inverse of square_rect_index
    Equivalent to list(square_rect(...))[index]"""
    dx = index % width
    dy = index // width
    assert dx >= 0 and dy < height
    return (rect_x + dx, rect_y + dy)