def test_poly(): conv = ToPointsAndSegments() # conv.add_polygon([[(0, 0), (10, 0), (11, -1), (12,0), (22,0), (14,10), (2,8), (0, 5), (0,0)]]) # FIXME: works but wrong: conv.add_polygon([[(0, 0), (9, 0), (11, -.1), (11.1, 0), (22, 0), (14, 10), (2, 8), (0, 5), (0, 0)]]) skel = calc_skel(conv, output=True, pause=True)
def test_diamant(): conv = ToPointsAndSegments() conv.add_polygon([[(-1, 0), (0, -1), (1, 0), (0, 5), (-1, 0)]]) # FIXME: works but wrong: # conv.add_polygon([[(0, 0), (9, 0), (11, -.1), (11.1,0), (22,0), (14,10), (2,8), (0, 5), (0,0)]]) skel = calc_skel(conv, pause=True, output=True) assert len(skel.segments()) == 8
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)
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_2triangle_1side_collapse(): conv = ToPointsAndSegments() #conv.add_point((8,2)) conv.add_polygon([[(0.1, 0), (10, 0), (9, 10), (2, 9.5), (0, 0.1), (0.1, 0)]]) skel = calc_skel(conv, pause=True, output=True) assert len(skel.segments()) == (7 + 5)
def test_pointy_star(): conv = ToPointsAndSegments() #conv.add_point((8,2)) conv.add_polygon([[(-5, 10), (-.1, 0), (-5, -10), (0, -9), (5, -10), (.1, 0), (5, 10), (0, 9), (-5, 10)]]) skel = calc_skel(conv, pause=True, output=True) assert len(skel.segments()) == 8
def test_tri_2intermediate_pts(): conv = ToPointsAndSegments() #conv.add_point((8,2)) conv.add_polygon([[(-1, 0), (-0.1, -1), (0.1, -1), (1, 0), (0, 14), (-1, 0)]]) skel = calc_skel(conv, pause=True, output=True) assert len(skel.segments()) == 8
def test_rocket(): """Contains zero triangle to flip ... """ ring = [(0, 0), (10, 0), (15, 5), (10, 9), (1, 7), (6, 4), (0, 0)] conv = ToPointsAndSegments() conv.add_polygon([ring]) skel = calc_skel(conv, output=True, pause=True) print "DONE"
def test_appendix_a4(): """Contains zero triangle to flip ... """ ring = [(0, 0), (1, 1), (2, 0), (6, 0), (6.1, 3), (2.5, 5.5), (-0.5, 3), (0, 0)] conv = ToPointsAndSegments() conv.add_polygon([ring]) skel = calc_skel(conv, output=True, pause=True) print "DONE"
def test_flip_loop(): """This has an infinite sequence in there... """ conv = ToPointsAndSegments() ring = [(0, 0), (3, 0), (3.8, 2), (4, 0), (6, 0), (6.3, 2), (7, 0), (10, 0), (13, 4), (10, 5), (7, 5), (6.5, 3), (6, 5), (4, 5), (3.5, 3), (3, 5), (0, 5), (-2, 2), (0, 0)] conv.add_polygon([ring]) skel = calc_skel(conv, pause=True, output=True)
def test_flip_loop2(): """This makes an infinite event loop with infinite triangles (because of flipping)! """ conv = ToPointsAndSegments() ring = [(0, 0), (3, 0), (3.8, 2), (5, 0), (6.3, 2), (7, 0), (10, 0), (13, 4), (10, 5), (7, 5), (6.5, 3), (5, 5), (3.5, 3), (3, 5), (0, 5), (-2, 2), (0, 0)] conv.add_polygon([ring]) skel = calc_skel(conv, pause=True, output=True)
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_cocircular1(): # FIXME: Point ok = (3.8, 0.8) # this works fail = (4, 1 ) # substitute with this and we get a lot of simultaneous events! conv = ToPointsAndSegments() conv.add_polygon([[(0, 1), (1, 0), (3, 0), ok, (4, 3), (3, 4), (1, 4), (0, 3), (0, 1)]]) # FIXME: works but wrong: # conv.add_polygon([[(0, 0), (9, 0), (11, -.1), (11.1,0), (22,0), (14,10), (2,8), (0, 5), (0,0)]]) calc_skel(conv, output=True, pause=True)
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_circular(): # massive simultaneous amount of events! from math import pi, cos, sin ring = [] pi2 = 2 * pi ct = 10 alpha = pi2 / ct for i in range(ct): ring.append((cos(i * alpha), sin(i * alpha))) ring.append(ring[0]) print ring conv = ToPointsAndSegments() conv.add_polygon([ring]) calc_skel(conv, output=True, pause=True)
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_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_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_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_bottom_circle_top_square(): # bottom circle from math import pi, cos, sin, degrees ring = [] pi2 = 2 * pi ct = 6 alpha = pi / ct print degrees(alpha) for i in range(ct + 1): ring.append((cos(pi + i * alpha), sin(pi + i * alpha))) ring.extend([(1, 10), (-1, 10)]) ring.append(ring[0]) conv = ToPointsAndSegments() conv.add_polygon([ring]) calc_skel(conv, pause=True, output=True)
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_2triangle(): from math import sqrt conv = ToPointsAndSegments() polygon = [[ (1, 0), #(-5, 0), (-4.25, -6.65),# (-1,-0.9), (1, -10), (11, -10), #(11,0), (11, 10), (1, 10), (1, 2), (1 - (sqrt(3)), 1), (1, 0) ]] conv.add_polygon(polygon) 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