Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
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"
Beispiel #7
0
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)
Beispiel #8
0
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)
Beispiel #9
0
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"
Beispiel #10
0
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)
Beispiel #11
0
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)
Beispiel #12
0
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)
Beispiel #13
0
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)
Beispiel #14
0
def test_simple_poly():
    conv = ToPointsAndSegments()
    conv.add_polygon([[(0, 0), (22, 0), (14, 10), (2, 8), (0, 6.5), (0, 0)]])
    skel = calc_skel(conv, output=True, pause=True)
    assert len(skel.segments()) == 12
Beispiel #15
0
def test_inf_teeth():
    conv = ToPointsAndSegments()
    ring = [(0, 7), (10, 0), (8, 8), (16, 8), (17, 0), (17.1, 10.5), (0, 10),
            (0, 7)]
    conv.add_polygon([ring])
    skel = calc_skel(conv, pause=True, output=True)
Beispiel #16
0
def test_cross():
    ring = [(0, 0), (10, 0), (10, -10), (15, -10), (15, 0), (25, 0), (25, 5),
            (15, 5), (15, 15), (10, 15), (10, 5), (0, 5), (0, 0)]
    conv = ToPointsAndSegments()
    conv.add_polygon([ring])
    skel = calc_skel(conv, output=True, pause=True)
Beispiel #17
0
def test_inf_quad():
    conv = ToPointsAndSegments()
    ring = [(0, 0), (4.2, 5.4), (6.9, 0.05), (10, 2), (5, 10), (0, 0)]
    conv.add_polygon([ring])
    skel = calc_skel(conv, pause=True, output=True)
Beispiel #18
0
def test_inf_flat():
    conv = ToPointsAndSegments()
    ring = [(0, 0), (10, 0), (50, 1), (90, 0), (100, 0), (49, 2), (0, 0)]
    conv.add_polygon([ring])
    skel = calc_skel(conv, pause=True, output=True)
Beispiel #19
0
def test_cocircular():
    conv = ToPointsAndSegments()
    conv.add_polygon([[(0, 1), (1, 0), (2, 0), (3, 1), (3, 2), (2, 3), (1, 3),
                       (0, 2), (0, 1)]])
    calc_skel(conv, output=True, pause=True)
Beispiel #20
0
def test_tri_intermediate_pt_sharp():
    conv = ToPointsAndSegments()
    #conv.add_point((8,2))
    conv.add_polygon([[(-1, 0), (0, 13.5), (1, 0), (0, 14), (-1, 0)]])
    skel = calc_skel(conv, output=True)
    assert len(skel.segments()) == 8
Beispiel #21
0
def test_parallellogram():
    conv = ToPointsAndSegments()
    conv.add_polygon([[(-15, 0), (0, 0), (15, 25), (0, 25), (-15, 0)]])
    calc_skel(conv)
Beispiel #22
0
def helper_make_test_collapse_time():
    from math import sqrt
    from tri import triangulate, ToPointsAndSegments
    from grassfire import init_skeleton
    #     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)]]
    #     from simplegeom.wkt import loads
    #     p = """
    #     POLYGON((-2.28464419475655456 -0.62568847763824631,-1.01123595505618002 0.05287508261731655,0.54857898215465939 0.05287508261731655,1.50914298303591066 -0.63450099140779903,1.27561136814276255 0.76228244106631404,0.46045384445913173 1.20731438642872879,-0.69839171623705676 1.20731438642872879,-1.72945582727473024 0.77109495483586699,-2.28464419475655456 -0.62568847763824631))\
    #     """
    #     polygon = loads(p)
    #     conv.add_polygon(polygon)

    conv = ToPointsAndSegments()
    conv.add_polygon([[(-1, 0), (0, -1), (1, 0), (0, 5), (-1, 0)]])

    #     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))

    conv = ToPointsAndSegments()
    ring = [(0, 0), (3, 0), (3.8, 2), (4, 0), (6, 0), (6.3, 2), (7, 0),
            (10, 0), (10, 5), (7, 5), (6.5, 3), (6, 5), (4, 5), (3.5, 3),
            (3, 5), (0, 5), (0, 0)]
    conv.add_polygon([ring])

    conv = ToPointsAndSegments()
    ring = [(0, 0), (3, 0), (3.8, 2), (4, 0), (6, 0), (6.3, 2), (7, 0),
            (10, 0), (10, 5), (7, 5), (6.5, 3), (6, 5), (4, 5), (3.5, 3),
            (3, 5), (0, 5), (0, 0)]
    conv.add_polygon([ring])

    conv = ToPointsAndSegments()
    ring = [(0, 0), (3, 0), (1.5, sqrt(3)), (0, 0)]
    conv.add_polygon([ring])
    dt = triangulate(conv.points, None, conv.segments)
    skel = init_skeleton(dt)
    print "triangles = {}"
    for t in skel.triangles:
        #         if t.finite:
        print "###", id(t)
        print "k = KineticTriangle()"
        print "V = []"
        for v in t.vertices:
            print "v = KineticVertex()"
            print "v.origin =", v.origin
            print "v.velocity =", v.velocity
            print "V.append(v)"
        print "k.vertices = V"
        print "triangles[", id(t), "] = k"
    print ""
    print "### neighbour relationships"
    for t in skel.triangles:
        print "n = [", ", ".join([
            "triangles[{0}]".format(id(n)) if n is not None else "None"
            for n in t.neighbours
        ]), "]"
        print "triangles[", id(t), "].neighbours = n"
Beispiel #23
0
def test_diamantlike():
    conv = ToPointsAndSegments()
    conv.add_polygon([[(-15, 0), (-1, 0), (0, -1), (1, 0), (15, 0), (0, 15),
                       (-15, 0)]])
    skel = calc_skel(conv, pause=True, output=True)
    assert len(skel.segments()) == (7 + 6)