def mergeCoords(A,B):
    """
    Takes two tuples and outputs two tuples, which will be identical 
    if the original overlap otherwise will be the originals

        A = (a1, a2), B = (b1, b2) and a1<=b1, a1<=a2, b1<=b2

        case 1: a2<=b1 ---> output originals
        case 2: b1<a2 && b2>a2 ---> output (a1, b2)
        case 3: b2<=a2 ---> output A
    """
    assert (min(A) <= min(B)), (
        'tuples given to mergeCoords in wrong order: A={0}, B={1}').format(A,B)

    if min(B) >= max(A):
        return ((A,B), 0)
    elif min(B) < max(A) and max(B) > max(A):
        output = (min(A),max(B))
        return ((output, output), 1)
    elif max(B) <= max(A):
        return ((A,A), 2)
    else:
        raise Exception(
            'Unexpected result from mergeCoords(A,B) using A={0}, B={1}'.format(
                                                                          A,B))