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_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_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_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_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_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_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_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_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_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_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_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_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_T_capital_T(self): """Capital T, has more than one triangle in parallel fan """ # T ring = [(15.5055, 28.7004), (20.8063, 28.7004), (20.8063, 44.1211), (26.7445, 44.1211), (26.7445, 47.8328), (9.5668, 47.8328), (9.5668, 44.1211), (15.5055, 44.1211), (15.5055, 28.7004)] conv = ToPointsAndSegments() conv.add_polygon([ring]) skel = calc_skel(conv, pause=PAUSE, output=OUTPUT) # check the amount of segments in the skeleton assert len(skel.segments()) == 21, len(skel.segments()) # check the amount of skeleton nodes assert len(skel.sk_nodes) == 14, len(skel.sk_nodes) # check the amount of kinetic vertices that are (not) stopped not_stopped = filter(lambda v: v.stops_at is None, skel.vertices) stopped = filter(lambda v: v.stops_at is not None, skel.vertices) assert len(not_stopped) == 8, len(not_stopped) assert len(stopped) == 13, len(stopped) # check cross relationship between kinetic vertices and skeleton nodes for v in skel.vertices: assert at_same_location((v.start_node, v), v.starts_at) if v.stops_at is not None and not v.inf_fast: assert at_same_location((v.stop_node, v), v.stops_at), \ "{} {} {}".format(id(v), v.stop_node.pos, v.position_at(v.stops_at) )
def test_another_parallel1(self): j = """{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::28992" } }, "features": [ { "type": "Feature", "properties": { "id": 21 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.673575314055, 0.166666666667 ], [ 0.866025403784, 0.166666666667 ] ] } }, { "type": "Feature", "properties": { "id": 25 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.673575314055, -0.166666666667 ], [ 0.5, -0.0 ] ] } }, { "type": "Feature", "properties": { "id": 27 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.866025403784, -0.166666666667 ], [ 0.673575314055, -0.166666666667 ] ] } }, { "type": "Feature", "properties": { "id": 32 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.5, -0.0 ], [ 0.673575314055, 0.166666666667 ] ] } } ] }""" import json x = json.loads(j) # parse segments from geo-json segments = [] for y in x['features']: segments.append(tuple(map(tuple, y['geometry']['coordinates']))) # convert to triangulation input conv = ToPointsAndSegments() for line in segments: conv.add_point(line[0]) conv.add_point(line[1]) conv.add_segment(*line) # skeletonize / offset skel = calc_skel(conv, pause=True, output=True)
def test_L_2(self): poly = [[(5, 0), (5, -1), (5, -2), (5, -3), (5, -4), (5, -5), (7, -5), (7, 0), (8, 0), (9, 0), (10, 0), (11, 0), (11, 1), (5, 1), (5, 0)]] # convert to triangulation input conv = ToPointsAndSegments() conv.add_polygon(poly) # skeletonize / offset skel = calc_skel(conv, pause=PAUSE, output=OUTPUT) # check the amount of segments in the skeleton assert len(skel.segments()) == 40, len(skel.segments()) # check the amount of skeleton nodes assert len(skel.sk_nodes) == 27, len(skel.sk_nodes) # check the amount of kinetic vertices that are (not) stopped assert len(filter(lambda v: v.stops_at is None, skel.vertices)) == 11 assert len(filter(lambda v: v.stops_at is not None, skel.vertices)) == 29 # check cross relationship between kinetic vertices and skeleton nodes for v in skel.vertices: assert at_same_location((v.start_node, v), v.starts_at) if v.stops_at is not None and not v.inf_fast: assert at_same_location((v.stop_node, v), v.stops_at), \ "{} {} {}".format(id(v), v.stop_node.pos, v.position_at(v.stops_at) )
def test_dent(self): """Simple parallel event """ conv = ToPointsAndSegments() lines = [[[0., 0.], [10., 0.]], [[10., 0.], [10., 10.]], [[10., 10.], [1., 10.]], [[1., 10.], [1., 7.]], [[1., 7.], [3., 7.]], [[3., 7.], [3., 6.5]], [[3., 6.5], [0., 6.5]], [[0., 6.5], [0., 0.]]] for line in lines: start, end = map(tuple, line) conv.add_point(start) conv.add_point(end) conv.add_segment(start, end) skel = calc_skel(conv, pause=PAUSE, output=OUTPUT, shrink=True) # check the amount of skeleton nodes assert len(skel.sk_nodes) == 16, len(skel.sk_nodes) # check the amount of segments in the skeleton assert len(skel.segments()) == 23, len(skel.segments()) # check the amount of kinetic vertices that are (not) stopped not_stopped = filter(lambda v: v.stops_at is None, skel.vertices) stopped = filter(lambda v: v.stops_at is not None, skel.vertices) assert len(not_stopped) == 6, len(not_stopped) assert len(stopped) == 17, len(stopped) # check cross relationship between kinetic vertices and skeleton nodes for v in skel.vertices: assert at_same_location((v.start_node, v), v.starts_at) if v.stops_at is not None and not v.inf_fast: assert at_same_location((v.stop_node, v), v.stops_at), \ "{} {} {}".format(id(v), v.stop_node.pos, v.position_at(v.stops_at) )
def test_another_parallel3(self): j = """{ "type": "FeatureCollection", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::28992" } }, "features": [ { "type": "Feature", "properties": { "id": 19 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.481125224325, 0.5 ], [ 0.288675134595, 0.5 ] ] } }, { "type": "Feature", "properties": { "id": 20 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.288675134595, 0.5 ], [ 0.19245008973, 0.666666666667 ] ] } }, { "type": "Feature", "properties": { "id": 24 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.19245008973, 0.666666666667 ], [ 0.288675134595, 0.833333333333 ] ] } }, { "type": "Feature", "properties": { "id": 44 }, "geometry": { "type": "LineString", "coordinates": [ [ 0.57735026919, 0.666666666667 ], [ 0.481125224325, 0.5 ] ] } } ] }""" import json x = json.loads(j) # parse segments from geo-json segments = [] for y in x['features']: segments.append(tuple(map(tuple, y['geometry']['coordinates']))) # convert to triangulation input conv = ToPointsAndSegments() for line in segments: conv.add_point(line[0]) conv.add_point(line[1]) conv.add_segment(*line) # skeletonize / offset skel = calc_skel(conv, pause=True, output=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_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_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_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_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_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_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)