def trace_overlap(xxx_todo_changeme, xxx_todo_changeme1, thresh=2.0):
    (wa, i) = xxx_todo_changeme
    (wb, j) = xxx_todo_changeme1

    def dist(ia, ib):
        (a, b) = (wa[ia], wb[ib])
        return hypot((a[0] - b[0]), (a[1] - b[1]))
    (ia, ib) = (i, j)
    if ((ia == (len(wa) - 1)) or (ib == (len(wb) - 1))):
        if ((ia != 0) and (ib != 0)):
            dax = (wa.x[(ia - 1)] - wa.x[ia])
            day = (wa.y[(ia - 1)] - wa.y[ia])
            dbx = (wb.x[(ib - 1)] - wb.x[ib])
            dby = (wb.y[(ib - 1)] - wb.y[ib])
        elif (ia == 0):
            dax = (wa.x[(ia + 1)] - wa.x[ia])
            day = (wa.y[(ia + 1)] - wa.y[ia])
            dbx = ((- wb.x[(ib - 1)]) + wb.x[ib])
            dby = ((- wb.y[(ib - 1)]) + wb.y[ib])
        elif (ib == 0):
            dax = ((- wa.x[(ia - 1)]) + wa.x[ia])
            day = ((- wa.y[(ia - 1)]) + wa.y[ia])
            dbx = (wb.x[(ib + 1)] - wb.x[ib])
            dby = (wb.y[(ib + 1)] - wb.y[ib])
    else:
        dax = (wa.x[(ia + 1)] - wa.x[ia])
        day = (wa.y[(ia + 1)] - wa.y[ia])
        dbx = (wb.x[(ib + 1)] - wb.x[ib])
        dby = (wb.y[(ib + 1)] - wb.y[ib])
    stepa = (- 1)
    enda = 0
    notend = (lambda i, n: (i > n))
    if (abs(dax) > abs(day)):
        if ((dax * dbx) < 0):
            stepa = 1
            enda = len(wa)
            notend = (lambda i, n: (i < (n - 1)))
    elif ((day * dby) < 0):
        stepa = 1
        enda = len(wa)
        notend = (lambda i, n: (i < (n - 1)))
    bnda = [i, i]
    bndb = [j, j]
    ms = 0
    while ((ms < thresh) and notend(ia, enda) and (ib > 0)):
        moves = (((ia + stepa), (ib - 1)), ((ia + stepa), ib), (ia, (ib - 1)))
        scores = [dist(iam, ibm) for (iam, ibm) in moves]
        ms = min(scores)
        for (idx, s) in enumerate(scores):
            if (s == ms):
                (ia, ib) = moves[idx]
                break
    if ((not notend(ia, enda)) and (ib == 0)):
        pass
    elif (not notend(ia, enda)):
        last = ms
        s = dist(ia, (ib - 1))
        while ((s < last) and (ib > 1)):
            ib -= 1
            last = s
            s = dist(ia, (ib - 1))
    elif (ib == 0):
        last = ms
        s = dist((ia + stepa), ib)
        while ((s < last) and notend(ia, (enda - stepa))):
            ia += stepa
            last = s
            s = dist((ia + stepa), ib)
    bnda[0] = ia
    bndb[0] = ib
    if (stepa == (- 1)):
        stepa = 1
        enda = len(wa)
        notend = (lambda i, n: (i < (n - 1)))
    else:
        stepa = (- 1)
        enda = 0
        notend = (lambda i, n: (i > n))
    (ia, ib) = (i, j)
    ms = 0
    while ((ms < thresh) and notend(ia, enda) and (ib < (len(wb) - 1))):
        moves = (((ia + stepa), (ib + 1)), ((ia + stepa), ib), (ia, (ib + 1)))
        scores = [dist(iam, ibm) for (iam, ibm) in moves]
        ms = min(scores)
        for (idx, s) in enumerate(scores):
            if (s == ms):
                (ia, ib) = moves[idx]
                break
    if ((not notend(ia, enda)) and (ib == (len(wb) - 1))):
        pass
    elif (not notend(ia, enda)):
        last = ms
        s = dist(ia, (ib + 1))
        while ((s < last) and (ib < (len(wb) - 2))):
            ib += 1
            last = s
            s = dist(ia, (ib + 1))
    elif (ib == (len(wb) - 1)):
        last = ms
        s = dist((ia + stepa), ib)
        while ((s < last) and notend(ia, (enda - stepa))):
            ia += stepa
            last = s
            s = dist((ia + stepa), ib)
    bnda[1] = ia
    bndb[1] = ib
    bnda.sort()
    return (bnda, bndb)
def trace_overlap(xxx_todo_changeme, xxx_todo_changeme1, thresh=2.0):
    (wa, i) = xxx_todo_changeme
    (wb, j) = xxx_todo_changeme1

    def dist(ia, ib):
        (a, b) = (wa[ia], wb[ib])
        return hypot((a[0] - b[0]), (a[1] - b[1]))
    (ia, ib) = (i, j)
    if ((ia == (len(wa) - 1)) or (ib == (len(wb) - 1))):
        if ((ia != 0) and (ib != 0)):
            dax = (wa.x[(ia - 1)] - wa.x[ia])
            day = (wa.y[(ia - 1)] - wa.y[ia])
            dbx = (wb.x[(ib - 1)] - wb.x[ib])
            dby = (wb.y[(ib - 1)] - wb.y[ib])
        elif (ia == 0):
            dax = (wa.x[(ia + 1)] - wa.x[ia])
            day = (wa.y[(ia + 1)] - wa.y[ia])
            dbx = ((- wb.x[(ib - 1)]) + wb.x[ib])
            dby = ((- wb.y[(ib - 1)]) + wb.y[ib])
        elif (ib == 0):
            dax = ((- wa.x[(ia - 1)]) + wa.x[ia])
            day = ((- wa.y[(ia - 1)]) + wa.y[ia])
            dbx = (wb.x[(ib + 1)] - wb.x[ib])
            dby = (wb.y[(ib + 1)] - wb.y[ib])
    else:
        dax = (wa.x[(ia + 1)] - wa.x[ia])
        day = (wa.y[(ia + 1)] - wa.y[ia])
        dbx = (wb.x[(ib + 1)] - wb.x[ib])
        dby = (wb.y[(ib + 1)] - wb.y[ib])
    stepa = (- 1)
    enda = 0
    notend = (lambda i, n: (i > n))
    if (abs(dax) > abs(day)):
        if ((dax * dbx) < 0):
            stepa = 1
            enda = len(wa)
            notend = (lambda i, n: (i < (n - 1)))
    elif ((day * dby) < 0):
        stepa = 1
        enda = len(wa)
        notend = (lambda i, n: (i < (n - 1)))
    bnda = [i, i]
    bndb = [j, j]
    ms = 0
    while ((ms < thresh) and notend(ia, enda) and (ib > 0)):
        moves = (((ia + stepa), (ib - 1)), ((ia + stepa), ib), (ia, (ib - 1)))
        scores = [dist(iam, ibm) for (iam, ibm) in moves]
        ms = min(scores)
        for (idx, s) in enumerate(scores):
            if (s == ms):
                (ia, ib) = moves[idx]
                break
    if ((not notend(ia, enda)) and (ib == 0)):
        pass
    elif (not notend(ia, enda)):
        last = ms
        s = dist(ia, (ib - 1))
        while ((s < last) and (ib > 1)):
            ib -= 1
            last = s
            s = dist(ia, (ib - 1))
    elif (ib == 0):
        last = ms
        s = dist((ia + stepa), ib)
        while ((s < last) and notend(ia, (enda - stepa))):
            ia += stepa
            last = s
            s = dist((ia + stepa), ib)
    bnda[0] = ia
    bndb[0] = ib
    if (stepa == (- 1)):
        stepa = 1
        enda = len(wa)
        notend = (lambda i, n: (i < (n - 1)))
    else:
        stepa = (- 1)
        enda = 0
        notend = (lambda i, n: (i > n))
    (ia, ib) = (i, j)
    ms = 0
    while ((ms < thresh) and notend(ia, enda) and (ib < (len(wb) - 1))):
        moves = (((ia + stepa), (ib + 1)), ((ia + stepa), ib), (ia, (ib + 1)))
        scores = [dist(iam, ibm) for (iam, ibm) in moves]
        ms = min(scores)
        for (idx, s) in enumerate(scores):
            if (s == ms):
                (ia, ib) = moves[idx]
                break
    if ((not notend(ia, enda)) and (ib == (len(wb) - 1))):
        pass
    elif (not notend(ia, enda)):
        last = ms
        s = dist(ia, (ib + 1))
        while ((s < last) and (ib < (len(wb) - 2))):
            ib += 1
            last = s
            s = dist(ia, (ib + 1))
    elif (ib == (len(wb) - 1)):
        last = ms
        s = dist((ia + stepa), ib)
        while ((s < last) and notend(ia, (enda - stepa))):
            ia += stepa
            last = s
            s = dist((ia + stepa), ib)
    bnda[1] = ia
    bndb[1] = ib
    bnda.sort()
    return (bnda, bndb)