def intersect(self, other_seg, tol=<NUM_LIT>):
<EOL>if (self.rotation == <NUM_LIT:0>) and isinstance(other_seg, Line):<EOL><INDENT>a = self.radius.real<EOL>b = self.radius.imag<EOL>l = Line(start=(other_seg.start-self.center), end=(other_seg.end-self.center))<EOL>p = l.poly()<EOL>if p[<NUM_LIT:1>].real == <NUM_LIT:0.0>:<EOL><INDENT>c = p[<NUM_LIT:0>].real<EOL>x_values = [c]<EOL>discriminant = <NUM_LIT:1> - (c * c)/(a * a)<EOL>if discriminant < <NUM_LIT:0>:<EOL><INDENT>return []<EOL><DEDENT>elif discriminant == <NUM_LIT:0>:<EOL><INDENT>y_values = [<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>val = b * sqrt(discriminant)<EOL>y_values = [val, -val]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>m = p[<NUM_LIT:1>].imag / p[<NUM_LIT:1>].real<EOL>c = (-m * p[<NUM_LIT:0>].real) + p[<NUM_LIT:0>].imag<EOL>denominator = (a * a * m * m) + (b * b)<EOL>discriminant = denominator - (c * c)<EOL>if discriminant < <NUM_LIT:0>:<EOL><INDENT>return []<EOL><DEDENT>x_sqrt = a * b * sqrt(discriminant)<EOL>x1 = (-(a * a * m * c) + x_sqrt) / denominator <EOL>x2 = (-(a * a * m * c) - x_sqrt) / denominator <EOL>x_values = [x1]<EOL>if x1 != x2:<EOL><INDENT>x_values.append(x2)<EOL><DEDENT>y_sqrt = x_sqrt * m<EOL>y1 = ((b * b * c) + y_sqrt) / denominator<EOL>y2 = ((b * b * c) - y_sqrt) / denominator<EOL>y_values = [y1]<EOL>if y1 != y2:<EOL><INDENT>y_values.append(y2)<EOL><DEDENT><DEDENT>intersections = []<EOL>for x in x_values:<EOL><INDENT>for y in y_values:<EOL><INDENT>p = complex(x, y) + self.center<EOL>my_t = self.point_to_t(p)<EOL>if my_t == None:<EOL><INDENT>continue<EOL><DEDENT>other_t = other_seg.point_to_t(p)<EOL>if other_t == None:<EOL><INDENT>continue<EOL><DEDENT>intersections.append([my_t, other_t])<EOL><DEDENT><DEDENT>return intersections<EOL><DEDENT>elif is_bezier_segment(other_seg):<EOL><INDENT>u1poly = self.u1transform(other_seg.poly())<EOL>u1poly_mag2 = real(u1poly)**<NUM_LIT:2> + imag(u1poly)**<NUM_LIT:2><EOL>t2s = polyroots01(u1poly_mag2 - <NUM_LIT:1>)<EOL>t1s = [self.phase2t(phase(u1poly(t2))) for t2 in t2s]<EOL>return list(zip(t1s, t2s))<EOL><DEDENT>elif isinstance(other_seg, Arc):<EOL><INDENT>assert other_seg != self<EOL>longer_length = max(self.length(), other_seg.length())<EOL>inters = bezier_intersections(self, other_seg,<EOL>longer_length=longer_length,<EOL>tol=tol, tol_deC=tol)<EOL>if len(inters) > <NUM_LIT:2>:<EOL><INDENT>def keyfcn(tpair):<EOL><INDENT>t1, t2 = tpair<EOL>return abs(self.point(t1) - other_seg.point(t2))<EOL><DEDENT>inters.sort(key=keyfcn)<EOL>for idx in range(<NUM_LIT:1>, len(inters)-<NUM_LIT:1>):<EOL><INDENT>if (abs(inters[idx][<NUM_LIT:0>] - inters[idx + <NUM_LIT:1>][<NUM_LIT:0>])<EOL><  abs(inters[idx][<NUM_LIT:0>] - inters[<NUM_LIT:0>][<NUM_LIT:0>])):<EOL><INDENT>return [inters[<NUM_LIT:0>], inters[idx]]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return [inters[<NUM_LIT:0>], inters[-<NUM_LIT:1>]]<EOL><DEDENT><DEDENT>return inters<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>
NOT FULLY IMPLEMENTED.  Finds the intersections of two segments.
        returns a list of tuples (t1, t2) such that
        self.point(t1) == other_seg.point(t2).
        Note: This will fail if the two segments coincide for more than a
        finite collection of points.

        Note: Arc related intersections are only partially supported, i.e. are
        only half-heartedly implemented and not well tested.  Please feel free
        to let me know if you're interested in such a feature -- or even better
        please submit an implementation if you want to code one.