def bezier_intersections(bez1, bez2, longer_length, tol=<NUM_LIT>, tol_deC=<NUM_LIT>):
maxits = int(ceil(<NUM_LIT:1>-log(tol_deC/longer_length)/log(<NUM_LIT:2>)))<EOL>pair_list = [BPair(bez1, bez2, <NUM_LIT:0.5>, <NUM_LIT:0.5>)]<EOL>intersection_list = []<EOL>k = <NUM_LIT:0><EOL>approx_point_set = ApproxSolutionSet(tol)<EOL>while pair_list and k < maxits:<EOL><INDENT>new_pairs = []<EOL>delta = <NUM_LIT:0.5>**(k + <NUM_LIT:2>)<EOL>for pair in pair_list:<EOL><INDENT>bbox1 = bezier_bounding_box(pair.bez1)<EOL>bbox2 = bezier_bounding_box(pair.bez2)<EOL>if boxes_intersect(bbox1, bbox2):<EOL><INDENT>if box_area(*bbox1) < tol_deC and box_area(*bbox2) < tol_deC:<EOL><INDENT>point = bezier_point(bez1, pair.t1)<EOL>if point not in approx_point_set:<EOL><INDENT>approx_point_set.append(point)<EOL>intersection_list.append((pair.t1, pair.t2))<EOL><DEDENT>for otherPair in pair_list:<EOL><INDENT>if pair.bez1 == otherPair.bez1 orpair.bez2 == otherPair.bez2 orpair.bez1 == otherPair.bez2 orpair.bez2 == otherPair.bez1:<EOL><INDENT>pair_list.remove(otherPair)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>(c11, c12) = halve_bezier(pair.bez1)<EOL>(t11, t12) = (pair.t1 - delta, pair.t1 + delta)<EOL>(c21, c22) = halve_bezier(pair.bez2)<EOL>(t21, t22) = (pair.t2 - delta, pair.t2 + delta)<EOL>new_pairs += [BPair(c11, c21, t11, t21),<EOL>BPair(c11, c22, t11, t22),<EOL>BPair(c12, c21, t12, t21),<EOL>BPair(c12, c22, t12, t22)]<EOL><DEDENT><DEDENT><DEDENT>pair_list = new_pairs<EOL>k += <NUM_LIT:1><EOL><DEDENT>if k >= maxits:<EOL><INDENT>raise Exception("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>return intersection_list<EOL>
INPUT:
    bez1, bez2 = [P0,P1,P2,...PN], [Q0,Q1,Q2,...,PN] defining the two
    Bezier curves to check for intersections between.
    longer_length - the length (or an upper bound) on the longer of the two
    Bezier curves.  Determines the maximum iterations needed together with tol.
    tol - is the smallest distance that two solutions can differ by and still
    be considered distinct solutions.
    OUTPUT: a list of tuples (t,s) in [0,1]x[0,1] such that
        abs(bezier_point(bez1[0],t) - bezier_point(bez2[1],s)) < tol_deC
    Note: This will return exactly one such tuple for each intersection
    (assuming tol_deC is small enough).