Example #1
0
def test_intersection2():    
    def r():
        return random.randint(-50,50)
    random.seed(0)
    for x in xrange(1000):
        la=Line(Vertex(r(),r()),Vertex(r(),r()))
        lb=Line(Vertex(r(),r()),Vertex(r(),r()))
        if not points(la).intersection(points(lb)):
            continue        
        ls=list(la.intersect2(lb))
        for a,b in all_pairs(ls):
            l2=list(a.intersect2(b))
            if len(l2)!=0:
                print "Problematic intersect: %s %s"%(la,lb)
                visualize_diff([
                                (la,(255,0,0)),
                                (lb,(0,255,0)),
                                (ls[0],(0,0,255)),
                                (ls[4],(0,0,255)),
                                ],[])
                visualize_diff([
                                (a,(255,0,0)),
                                (b,(0,255,0)),
                                (l2[0],(0,0,255)),
                                ],[])
                
            assert len(l2)==0
Example #2
0
def test_intersection_ex1():    
    la=Line(Vertex(5,5),Vertex(3,2))
    lb=Line(Vertex(4,1),Vertex(4,5))
    print "la: %s, lb: %s"%(la,lb)
    ls=list(la.intersection_points(lb))
    print "ls:",ls
    #visualize_diff([
    #                (la,(255,0,0)),
    #                (lb,(0,255,0)),
    #                ],[])
    ls=list(la.intersect2(lb))
    print "Ls:",ls