def remove_intersections(ipath, jpath, iclosed, jclosed, iringupdated=False, jringupdated=False):
    new_ipath = ipath
    new_jpath = jpath
    res = ipath.intersect(jpath, justonemode=True)
    if res:
        (iT, iseg, i_t) = res[0]
        (jT, jseg, j_t) = res[1]
    else:
        run_again = False
        return (new_ipath, new_jpath, iringupdated, jringupdated, run_again)
    if (iclosed and jclosed):
        raise ClosedRingsOverlapError('')
    elif jclosed:
        new_ipath = longPart(ipath, iT)
        new_jpath = jpath
        iringupdated = True
    elif iclosed:
        new_jpath = longPart(jpath, jT)
        new_ipath = ipath
        jringupdated = True
    elif (iT in [0, 1]):
        new_ipath = longPart(ipath, iT)
        new_jpath = jpath
        iringupdated = True
    elif (jT in [0, 1]):
        new_jpath = longPart(jpath, jT)
        new_ipath = ipath
        jringupdated = True
    elif (shortPart(ipath, iT).length() < shortPart(jpath, jT).length()):
        new_ipath = longPart(ipath, iT)
        new_jpath = jpath
        iringupdated = True
    else:
        new_jpath = longPart(jpath, jT)
        new_ipath = ipath
        jringupdated = True
    run_again = True
    return (new_ipath, new_jpath, iringupdated, jringupdated, run_again)
def remove_intersections(ipath, jpath, iclosed, jclosed, iringupdated=False, jringupdated=False):
    new_ipath = ipath
    new_jpath = jpath
    res = ipath.intersect(jpath, justonemode=True)
    if res:
        (iT, iseg, i_t) = res[0]
        (jT, jseg, j_t) = res[1]
    else:
        run_again = False
        return (new_ipath, new_jpath, iringupdated, jringupdated, run_again)
    if (iclosed and jclosed):
        raise ClosedRingsOverlapError()
    elif jclosed:
        new_ipath = longPart(ipath, iT)
        new_jpath = jpath
        iringupdated = True
    elif iclosed:
        new_jpath = longPart(jpath, jT)
        new_ipath = ipath
        jringupdated = True
    elif (iT in [0, 1]):
        new_ipath = longPart(ipath, iT)
        new_jpath = jpath
        iringupdated = True
    elif (jT in [0, 1]):
        new_jpath = longPart(jpath, jT)
        new_ipath = ipath
        jringupdated = True
    elif (shortPart(ipath, iT).length() < shortPart(jpath, jT).length()):
        new_ipath = longPart(ipath, iT)
        new_jpath = jpath
        iringupdated = True
    else:
        new_jpath = longPart(jpath, jT)
        new_ipath = ipath
        jringupdated = True
    run_again = True
    return (new_ipath, new_jpath, iringupdated, jringupdated, run_again)