Esempio n. 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)
Esempio n. 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)
Esempio n. 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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 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"
Esempio n. 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)
Esempio n. 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)
Esempio n. 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"
Esempio n. 10
0
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
Esempio n. 11
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)
Esempio n. 12
0
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)
Esempio n. 13
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)
Esempio n. 14
0
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)
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
0
def test_1_segment():

    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)
Esempio n. 18
0
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
Esempio n. 19
0
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)
Esempio n. 20
0
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
Esempio n. 21
0
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)
Esempio n. 22
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
Esempio n. 23
0
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)
Esempio n. 24
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)
Esempio n. 25
0
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
Esempio n. 26
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)
Esempio n. 27
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)
Esempio n. 28
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)
Esempio n. 29
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"
Esempio n. 30
0
def test_parallellogram():
    conv = ToPointsAndSegments()
    conv.add_polygon([[(-15, 0), (0, 0), (15, 25), (0, 25), (-15, 0)]])
    calc_skel(conv)