def junction_coord(cells, direction=DOWN):
            """
            Under the hood: given two cells and a favoured direction, get the
            position of the cell with the column of one and the row of the
            other:

            A---->+
            |     ^
            |     |
            |     |
            v     |
            *<----B

            Both + and * are candidates for the junction of A and B - we take
            the one furthest down by default (specified by direction)

            >>> cells_dr = (_XYCell(0,1,2,None), _XYCell(0,3,4,None))
            >>> junction_coord(cells_dr, DOWN)
            (1, 4)
            >>> junction_coord(cells_dr, UP)
            (3, 2)
            >>> junction_coord(cells_dr, LEFT)
            (1, 4)
            >>> junction_coord(cells_dr, RIGHT)
            (3, 2)
            >>> cells_tr = (_XYCell(0,1,4,None), _XYCell(0,3,2,None))
            >>> junction_coord(cells_tr, DOWN)
            (3, 4)
            >>> junction_coord(cells_tr, UP)
            (1, 2)
            >>> junction_coord(cells_tr, LEFT)
            (1, 2)
            >>> junction_coord(cells_tr, RIGHT)
            (3, 4)
            """


            new_cells = (
                        (cells[0].x, cells[1].y),
                        (cells[1].x, cells[0].y)
            )
            for index, value in enumerate(direction):
                if value == 0:
                    continue
                if cmp(new_cells[0][index], new_cells[1][index]) == value:
                    return new_cells[0]
                else:
                    return new_cells[1]