예제 #1
0
    def test_equal_sides(self):
        t = self.triangles[139708485589200]
        bottom = compute_collapse_time(t)

        t = self.triangles[139708485589264]
        top = compute_collapse_time(t)

        print bottom.time == top.time
예제 #2
0
def test_compute_3():
    tri = KineticTriangle()
    a = KineticVertex()
    a.origin = (0, 0)
    a.velocity = (sqrt(2), sqrt(2))
    b = KineticVertex()
    b.origin = (1, 0)
    b.velocity = (-sqrt(2), sqrt(2))
    c = KineticVertex()
    c.origin = (0.5, 1)
    c.velocity = (0, -1)
    tri.neighbours = [None, None, None]  # make them None for the test
    tri.vertices = [a, b, c]
    print compute_collapse_time(tri)
    with open("/tmp/ktris.wkt", "w") as fh:
        output_triangles([tri], fh)
예제 #3
0
 def test_1tri(self):
     t = self.triangles[139643876357776]
     print t.str_at(2.5)
     evt = compute_collapse_time(t, now=0)
     pos = [v.position_at(evt.time) for v in t.vertices]
     print "orientation", orient2d(*pos)
     assert evt is not None
     print evt
예제 #4
0
파일: loop.py 프로젝트: bmmeijers/grassfire
def init_event_list(skel):
    """Compute for all kinetic triangles when they will collapse and
    put them in an OrderedSequence, so that events are ordered properly
    for further processing
    """
    q = OrderedSequence(cmp=compare_event_by_time)
    logging.debug("Calculate initial events")
    logging.debug("=" * 80)
    for tri in skel.triangles:
        res = compute_collapse_time(tri, 0, find_gt)
        if res is not None:
            q.add(res)
    logging.debug("=" * 80)
    return q
예제 #5
0
    def test_0tri(self):
        t = self.triangles[139643876356560]
        print t.str_at(0)
        print t.neighbours
        evt = compute_collapse_time(t, now=0)
        print t.str_at(evt.time)
        pos = [v.position_at(evt.time) for v in t.vertices]
        for v in t.vertices:
            print v.origin
            print v.velocity
        times = []
        #         for side in range(3):
        #             i, j = cw(side), ccw(side)
        #             v1, v2 = t.vertices[i], t.vertices[j]
        #             times.append((collapse_time_edge(v1, v2), side))
        side = 0
        i, j = cw(side), ccw(side)
        v1, v2 = t.vertices[i], t.vertices[j]
        time = collapse_time_edge(v1, v2)
        times.append(time)
        side = 2
        i, j = cw(side), ccw(side)
        v1, v2 = t.vertices[i], t.vertices[j]
        with open("/tmp/cpa.csv", "w") as fh:
            for i, inc in enumerate(range(100, 150), start=1):
                val = inc / 1000.
                v1.position_at(val)
                v2.position_at(val)
                print >> fh, val, ";", sqrt(v1.distance2_at(v2, val))
        time = collapse_time_edge(v1, v2)
        times.append(time)
        for time in times:
            print "", time
        from datetime import datetime, timedelta

        with open("/tmp/kinetic.wkt", "w") as fh:
            fh.write("start;end;wkt\n")
            prev = datetime(2015, 1, 1)
            #prev = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
            for inc in range(100, 150):
                val = inc / 1000.
                cur = prev
                fh.write("{};{};{}\n".format(prev, cur, t.str_at(val)))
                prev = cur + timedelta(days=1)
        print "times", times
        print "orientation", orient2d(*pos)
        assert evt is not None
        print evt
예제 #6
0
def replace_in_queue(t, now, queue, immediate):
    """Replace event for a triangle in the queue """
    if t.event is not None:
        queue.discard(t.event)
        if t.event in immediate:
            immediate.remove(t.event)
    else:
        logging.debug(
            "triangle #{0} without event not removed from queue".format(
                id(t)))

###    logging.debug(" collapse time computation for: {}".format(str(repr(t)).replace(",",",\n\t")))
    e = compute_collapse_time(t, now)
    if e is not None:
        # if t.info in (548,550):
        #     logging.debug("""
        #     >>>
        #     """)
        logging.debug("new event in queue {}".format(e))
        queue.add(e)
    else:
        logging.debug("no new events".format(e))
        return
예제 #7
0
 def test_3triangle(self):
     evt = compute_collapse_time(
         self.triangles[139742234434064])  #, now=0.)
     assert evt.time == 4.281470067903971
예제 #8
0
 def test_inf_triangle2(self):
     evt = compute_collapse_time(
         self.triangles[139742234433616])  #, now=0.)
     assert evt is None