def test_multi_segment_cross_share_point():
    """
    two segments that share a point should not be reported as crossing
    """
    points = np.array( ( (3.0, 5.0),
                         (2.0, 2.0),
                         (5.0, 2.0),
                         (7.0, 4.0),
                         (6.0, 6.0),
                         (4.0, 7.0),
                         (7.0, 2.0),
                       ), dtype=np.float64)

    segments = np.array( ( (0, 1),
                           (1, 2),
                           ), dtype = np.int32)
    crosses =  multi_segment_cross(points, segments)
    assert crosses == []

    segments = np.array( ( (1, 2),
                           (0, 1),
                           ), dtype = np.int32)
    crosses =  multi_segment_cross(points, segments)
    assert crosses == []

    segments = np.array( ( (0, 1),
                           (2, 1),
                           ), dtype = np.int32)
    crosses =  multi_segment_cross(points, segments)
    assert crosses == []

    segments = np.array( ( (2, 1),
                           (0, 1),
                           ), dtype = np.int32)
    crosses =  multi_segment_cross(points, segments)
    assert crosses == []
def test_multi_segment_cross_share_both_points():
    """
    two segments that share both points should be reported as crossing
    """
    points = np.array( ( (3.0, 5.0),
                         (2.0, 2.0),
                         (5.0, 2.0),
                         (7.0, 4.0),
                         (6.0, 6.0),
                         (4.0, 7.0),
                         (7.0, 2.0),
                       ), dtype=np.float64)

    segments = np.array( ( (0, 1),
                           (1, 0),
                           (3, 2),
                           (2, 3),
                           ), dtype = np.int32)

    crosses =  multi_segment_cross(points, segments)
    assert crosses == [(0,1),(2,3)]
def test_multi_segment_cross():
    """
    tests the mult-segment cross function
    
    this does a lot of segment cross checks, where the segments are defined on a seprate array of points
    """
    points = np.array( ( (3.0, 5.0),
                         (2.0, 2.0),
                         (5.0, 2.0),
                         (7.0, 4.0),
                         (6.0, 6.0),
                         (4.0, 7.0),
                         (7.0, 2.0),
                       ), dtype=np.float64)
    segments = np.array( ( (1, 4),
                           (2, 5),
                           (3, 6),
                           ), dtype = np.int32)
    
    crosses =  multi_segment_cross(points, segments)
    
    assert crosses == [(0,1)]
                break                    
            elif p12 == p21:
                #print "second point matches first point"
                break                    
            elif p12 == p22:
                #print "second point matches second point"
                break                    
            s2 = points[lines[j,0]], points[lines[j,1]]
            if segment_cross(s1, s2):
                crosses.append( (i,j) )
    return crosses

points, lines = make_data(n_p, n_l)

sol1 = check_all(points, lines)
sol2 = multi_segment_cross(points, lines)
assert  sol1 == sol2

print "time for python version:",
print  timeit.timeit("check_all(points, lines)",
                     "from __main__ import check_all, points, lines",
                     number=10)

print "time for cython version:",
print  timeit.timeit("multi_segment_cross(points, lines)",
                     "from __main__ import multi_segment_cross, points, lines",
                     number=10)