コード例 #1
0
ファイル: test_stress.py プロジェクト: bgr/quadpy
 def test_insert_and_reinsert(self, quadtree_bounds, max_depth):
     params = quadtree_bounds + (max_depth,)
     qt = Node(*params)
     rect = random_rectangle(quadtree_bounds)
     print 'Testing with {0}, {1}'.format(qt, rect)  # shown if test fails
     assert qt.direct_children == []
     assert qt.get_children() == []
     qt.insert(rect)
     assert qt.get_children() == [rect]
     qt.reinsert(rect)
     assert qt.get_children() == [rect]
コード例 #2
0
 def test_insert_and_reinsert(self, quadtree_bounds, max_depth):
     params = quadtree_bounds + (max_depth, )
     qt = Node(*params)
     rect = random_rectangle(quadtree_bounds)
     print 'Testing with {0}, {1}'.format(qt, rect)  # shown if test fails
     assert qt.direct_children == []
     assert qt.get_children() == []
     qt.insert(rect)
     assert qt.get_children() == [rect]
     qt.reinsert(rect)
     assert qt.get_children() == [rect]
コード例 #3
0
    def test(self, n_elems, quadtree_bounds, max_depth, change_bounds):
        rects = [random_rectangle(quadtree_bounds) for _ in range(n_elems)]
        params = quadtree_bounds + (max_depth, )
        qt = Node(*params)
        [qt.insert(r) for r in rects]
        key = lambda r: r.bounds
        assert sorted(qt.get_children(), key=key) == sorted(rects, key=key)
        assert len(qt.get_children()) == n_elems

        shuffle(rects)

        for r in rects:
            if change_bounds:
                new_bounds = random_rectangle(quadtree_bounds).bounds
                r.bounds = new_bounds
            qt.reinsert(r)
            assert sorted(qt.get_children(), key=key) == sorted(rects, key=key)
コード例 #4
0
ファイル: test_stress.py プロジェクト: bgr/quadpy
    def test(self, n_elems, quadtree_bounds, max_depth, change_bounds):
        rects = [random_rectangle(quadtree_bounds) for _ in range(n_elems)]
        params = quadtree_bounds + (max_depth,)
        qt = Node(*params)
        [qt.insert(r) for r in rects]
        key = lambda r: r.bounds
        assert sorted(qt.get_children(), key=key) == sorted(rects, key=key)
        assert len(qt.get_children()) == n_elems

        shuffle(rects)

        for r in rects:
            if change_bounds:
                new_bounds = random_rectangle(quadtree_bounds).bounds
                r.bounds = new_bounds
            qt.reinsert(r)
            assert sorted(qt.get_children(), key=key) == sorted(rects, key=key)
コード例 #5
0
ファイル: test_basic.py プロジェクト: h4ck3rm1k3/quadpy
    def test_reinsert_into_same_quadrant(self, max_depth):
        bounds = (0.001, 0.001, 0.002, 0.002)
        qt = Node(0, 0, 1024, 1024, max_depth)
        assert qt._get_depth() == 0
        assert qt._get_number_of_nodes() == 1
        rect = Rectangle(*bounds)

        qt.insert(rect)
        assert qt._get_depth() == max_depth
        assert qt._get_number_of_nodes() == 1 + max_depth * 4
        # make sure that top-left quadrant is the only one subdivided
        depths = [qt.quadrants[i]._get_depth() for i in range(4)]
        assert depths == [max_depth - 1, 0, 0, 0]

        # change coords and reinsert into same place
        qt.reinsert(rect)
        assert qt._get_depth() == max_depth
        assert qt._get_number_of_nodes() == 1 + max_depth * 4
        depths = [qt.quadrants[i]._get_depth() for i in range(4)]
        assert depths == [max_depth - 1, 0, 0, 0]
コード例 #6
0
    def test_reinsert_into_same_quadrant(self, max_depth):
        bounds = (0.001, 0.001, 0.002, 0.002)
        qt = Node(0, 0, 1024, 1024, max_depth)
        assert qt._get_depth() == 0
        assert qt._get_number_of_nodes() == 1
        rect = Rectangle(*bounds)

        qt.insert(rect)
        assert qt._get_depth() == max_depth
        assert qt._get_number_of_nodes() == 1 + max_depth * 4
        # make sure that top-left quadrant is the only one subdivided
        depths = [qt.quadrants[i]._get_depth() for i in range(4)]
        assert depths == [max_depth - 1, 0, 0, 0]

        # change coords and reinsert into same place
        qt.reinsert(rect)
        assert qt._get_depth() == max_depth
        assert qt._get_number_of_nodes() == 1 + max_depth * 4
        depths = [qt.quadrants[i]._get_depth() for i in range(4)]
        assert depths == [max_depth - 1, 0, 0, 0]
コード例 #7
0
ファイル: test_basic.py プロジェクト: h4ck3rm1k3/quadpy
    def test_reinsert_into_another_quadrant(self, max_depth):
        bounds_1 = (0.01, 0.01, 0.02, 0.02)
        bounds_2 = (1023.998, 1023.998, 1023.999, 1023.999)
        qt = Node(0, 0, 1024, 1024, max_depth)
        assert qt._get_depth() == 0
        assert qt._get_number_of_nodes() == 1
        rect = Rectangle(*bounds_1)
        qt.insert(rect)
        assert qt._get_depth() == max_depth
        assert qt._get_number_of_nodes() == 1 + max_depth * 4

        # make sure that top-left quadrant is the only one subdivided
        depths = [qt.quadrants[i]._get_depth() for i in range(4)]
        assert depths == [max_depth - 1, 0, 0, 0]

        # change coords and reinsert
        rect.bounds = bounds_2
        qt.reinsert(rect)
        assert qt._get_depth() == max_depth
        assert qt._get_number_of_nodes() == 1 + max_depth * 4

        # make sure that bottom-right quadrant is the only one subdivided
        depths = [qt.quadrants[i]._get_depth() for i in range(4)]
        assert depths == [0, 0, 0, max_depth - 1]
コード例 #8
0
    def test_reinsert_into_another_quadrant(self, max_depth):
        bounds_1 = (0.01, 0.01, 0.02, 0.02)
        bounds_2 = (1023.998, 1023.998, 1023.999, 1023.999)
        qt = Node(0, 0, 1024, 1024, max_depth)
        assert qt._get_depth() == 0
        assert qt._get_number_of_nodes() == 1
        rect = Rectangle(*bounds_1)
        qt.insert(rect)
        assert qt._get_depth() == max_depth
        assert qt._get_number_of_nodes() == 1 + max_depth * 4

        # make sure that top-left quadrant is the only one subdivided
        depths = [qt.quadrants[i]._get_depth() for i in range(4)]
        assert depths == [max_depth - 1, 0, 0, 0]

        # change coords and reinsert
        rect.bounds = bounds_2
        qt.reinsert(rect)
        assert qt._get_depth() == max_depth
        assert qt._get_number_of_nodes() == 1 + max_depth * 4

        # make sure that bottom-right quadrant is the only one subdivided
        depths = [qt.quadrants[i]._get_depth() for i in range(4)]
        assert depths == [0, 0, 0, max_depth - 1]