def test_infinite2(): """3 segments with terminal vertices at convex hull """ conv = ToPointsAndSegments() # l0 = [(0.0, -1.0), (5.0, -1.0)] # l1 = [(5.86602540378, 0.5), (3.36602540378, 4.83012701892)] # l2 = [(1.63397459622, 4.83012701892), (-0.866025403784, 0.5)] l0 = [(0.032020441647887, 0.050549836508082), (0.556388841835153, 0.835771552524547)] l1 = [(0.597646254032629, 0.835771552524547), (1.133992612599807, 0.029255688277127)] l2 = [(1.118022001426591, -0.000023765540436), (0.065292548258754, -0.000023765540436)] for line in l0, l1, l2: conv.add_point(line[0]) conv.add_point(line[1]) conv.add_segment(*line) skel = calc_skel(conv, pause=True, output=True) print skel.vertices print skel.triangles # # tmp_events(skel) # el = init_event_list(skel) # event_loop(el, skel, pause=True) return
def test_infinite(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((1, 0)) conv.add_segment((0, 0), (1, 0)) calc_skel(conv, pause=True, output=True)
def test_three_lines(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_point((-2, 8)) conv.add_point((-2, -8)) conv.add_segment((0, 0), (10, 0)) conv.add_segment((0, 0), (-2, 8)) conv.add_segment((0, 0), (-2, -8)) skel = calc_skel(conv, output=True, pause=True)
def test_triangle(): conv = ToPointsAndSegments() conv.add_point((10, 0)) conv.add_point((-2, 8)) conv.add_point((-2, -8)) conv.add_segment((10, 0), (-2, 8)) conv.add_segment((-2, 8), (-2, -8)) conv.add_segment((-2, -8), (10, 0)) skel = calc_skel(conv) assert len(skel.segments()) == 6
def test_two_lines_par(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_point((12, 1)) conv.add_point((22, 1)) conv.add_segment((0, 0), (10, 0)) conv.add_segment((12, 1), (22, 1)) calc_skel(conv)
def test_30_deg_segments(): conv = ToPointsAndSegments() conv.add_point((0, 5)) conv.add_point((9, 0.5)) conv.add_point((12, 2)) conv.add_point((14, 4)) conv.add_segment((0, 5), (9, 0.5)) conv.add_segment((12, 2), (14, 4)) calc_skel(conv)
def test_2_perp_segments(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_point((12, 2)) conv.add_point((12, 10)) conv.add_segment((0, 0), (10, 0)) conv.add_segment((12, 2), (12, 10)) calc_skel(conv)
def test_2_segments(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_point((22, 0)) conv.add_point((30, 0)) conv.add_segment((0, 0), (10, 0)) conv.add_segment((22, 0), (30, 0)) calc_skel(conv)
def test_45_deg_segments(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_point((12, 2)) conv.add_point((14, 4)) conv.add_segment((0, 0), (10, 0)) conv.add_segment((12, 2), (14, 4)) calc_skel(conv)
def test_parallel_movement(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((1, 0)) conv.add_point((2, 0)) conv.add_point((3, 0)) conv.add_segment((0, 0), (1, 0)) conv.add_segment((1, 0), (2, 0)) conv.add_segment((2, 0), (3, 0)) calc_skel(conv)
def test_polyline(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, -1)) conv.add_point((22, 1)) conv.add_point((30, -5)) conv.add_segment((0, 0), (10, -1)) conv.add_segment((10, -1), (22, 1)) conv.add_segment((22, 1), (30, -5)) calc_skel(conv)
def test_quad(): conv = ToPointsAndSegments() #conv.add_point((8,2)) conv.add_point((4, 5)) conv.add_point((-2, 8)) conv.add_point((-2, -8)) conv.add_point((14, 10)) #conv.add_segment((8,2), (14,10)) conv.add_segment((14, 10), (-2, 8)) conv.add_segment((-2, 8), (-2, -8)) #conv.add_segment((-2,-8), (8,2)) conv.add_segment((4, 5), (14, 10)) conv.add_segment((-2, -8), (4, 5)) skel = calc_skel(conv) assert len(skel.segments()) == 9
def test_crash_vertex(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((1, 0)) conv.add_point((0, 2)) conv.add_point((0.5, 1.5)) conv.add_point((1, 2)) conv.add_segment((0, 0), (1, 0)) conv.add_segment((0, 2), (0.5, 1.5)) conv.add_segment((1, 2), (0.5, 1.5)) calc_skel(conv)
def test_split(): conv = ToPointsAndSegments() #conv.add_point((8,2)) conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_point((10, 20)) close = (5, 4) conv.add_point(close) conv.add_point((0, 20)) #conv.add_segment((8,2), (14,10)) conv.add_segment((0, 0), (10, 0)) conv.add_segment((10, 0), (10, 20)) conv.add_segment((10, 20), close) conv.add_segment(close, (0, 20)) #conv.add_segment((-2,-8), (8,2)) conv.add_segment((0, 20), (0, 0)) skel = calc_skel(conv, pause=True, output=True) assert len(skel.segments()) == 12
def test_infinite3(): """6 segments with terminal vertices at convex hull """ from math import sqrt conv = ToPointsAndSegments() l0 = [(0.0, 1.0), (1.0, 1.0)] l1 = [(1, 1), (1, 0)] l2 = [(5, 0), ( 5, 1, )] l3 = [(5, 1), ( 6, 1, )] l4 = [(2, 2 + sqrt(3) / 2. * 4), ( 3, 1 + sqrt(3) / 2. * 4, )] l5 = [(3, 1 + sqrt(3) / 2. * 4), (4, 2 + sqrt(3) / 2. * 4)] # l0 = [ ( 0.032020441647887, 0.050549836508082), (0.556388841835153, 0.835771552524547) ] # l1 = [ ( 0.597646254032629, 0.835771552524547), (1.133992612599807, 0.029255688277127) ] # l2 = [ ( 1.118022001426591, -0.000023765540436), (0.065292548258754, -0.000023765540436) ] for line in l0, l1, l2, l3, l4, l5: conv.add_point(line[0]) conv.add_point(line[1]) conv.add_segment(*line) # FIXME: BUG here with respect to generating infinite triangles # ==> Around (5,0) there should be infinite triangle!! # it seems to be there, but inserted at the wrong location. # (so it remains flat from the start... -- can have to do with the is_quad # part of the creation of initial triangulation) skel = calc_skel(conv, pause=True, output=True) print skel.vertices print skel.triangles # # tmp_events(skel) el = init_event_list(skel) event_loop(el, skel, pause=True) return
def test_cocircular_segments(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((1, 1)) conv.add_point((3, 0)) conv.add_point((2, 1)) conv.add_point((0, 3)) conv.add_point((1, 2)) conv.add_point((3, 3)) conv.add_point((2, 2)) conv.add_segment((0, 0), (1, 1)) conv.add_segment((3, 0), (2, 1)) conv.add_segment((0, 3), (1, 2)) conv.add_segment((3, 3), (2, 2)) calc_skel(conv)
def test_arrow_four_lines(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_point((12, 0.5)) conv.add_point((8, 5)) conv.add_point((8, -5)) conv.add_segment((0, 0), (10, 0)) conv.add_segment((8, 5), (12, 0.5)) conv.add_segment((12, 0.5), (8, -5)) calc_skel(conv)
def test_single_line(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_segment((0, 0), (10, 0)) calc_skel(conv)
def test_4_segments(): conv = ToPointsAndSegments() conv.add_point((0, 0)) conv.add_point((10, 0)) conv.add_point((22, 0)) conv.add_point((30, 0)) conv.add_point((16, -3)) conv.add_point((16, -6)) conv.add_point((16, 2)) conv.add_point((16, 6)) conv.add_segment((0, 0), (10, 0)) conv.add_segment((22, 0), (30, 0)) conv.add_segment((16, -3), (16, -6)) conv.add_segment((16, 2), (16, 6)) conv.add_segment((0, 0), (16, -6)) conv.add_segment((16, -6), (30, 0)) conv.add_segment((30, 0), (16, 6)) conv.add_segment((16, 6), (0, 0)) calc_skel(conv)