Пример #1
0
    def test_quadtree_search(self):
        vertices = [(x, x**2) for x in np.linspace(-10, 10, 1000)]
        cs = CoordString(vertices)
        quadtree = QuadTree(cs)

        indices_within = quadtree.search_within(-5, 0, 5, 25)
        self.assertEqual(len(indices_within), 500)
        self.assertEqual(min(indices_within), 250)
        self.assertEqual(max(indices_within), 749)
        return
Пример #2
0
 def test_quadtree_duplicates(self):
     # a naive quadtree with enter an infinite loop when there are
     # duplicates exceeding leaf node capacity. this test ensures that this
     # doesn't happen, and that the duplicate points can be retrieved
     vertices = [(3.0, 4.0) for _ in range(11)]
     cs = CoordString(vertices)
     quadtree = QuadTree(cs, leaf_capacity=10)
     indices_within = quadtree.search_within(2, 3, 4, 5)
     self.assertEqual(len(indices_within), 11)
     return
Пример #3
0
    def test_quadtree_search(self):
        vertices = [(x, x**2) for x in np.linspace(-10, 10, 1000)]
        cs = CoordString(vertices)
        quadtree = QuadTree(cs)

        indices_within = quadtree.search_within(-5, 0, 5, 25)
        self.assertEqual(len(indices_within), 500)
        self.assertEqual(min(indices_within), 250)
        self.assertEqual(max(indices_within), 749)
        return
Пример #4
0
 def test_quadtree_duplicates(self):
     # a naive quadtree with enter an infinite loop when there are
     # duplicates exceeding leaf node capacity. this test ensures that this
     # doesn't happen, and that the duplicate points can be retrieved
     vertices = [(3.0, 4.0) for _ in range(11)]
     cs = CoordString(vertices)
     quadtree = QuadTree(cs, leaf_capacity=10)
     indices_within = quadtree.search_within(2, 3, 4, 5)
     self.assertEqual(len(indices_within), 11)
     return
Пример #5
0
 def test_quadtree_add_bbox(self):
     pts = [(x**0.5, 0.5 * y**0.875) for x in range(50) for y in range(50)]
     QTree = QuadTree((0, 0, 32, 22))
     for pt in pts:
         QTree.addpt(pt)
     pts = QTree.getfrombbox((16, 8, 24, 12))
     ans = [pt for pt in pts if (16 <= pt[0] < 24) and (8 <= pt[1] < 12)]
     pts.sort()
     ans.sort()
     self.assertEqual(pts, ans)
     return
Пример #6
0
 def test_quadtree_add_bbox(self):
     pts = [(x**0.5,0.5*y**0.875) for x in range(50) for y in range(50)]
     QTree = QuadTree((0, 32, 0, 22))
     for pt in pts:
         QTree.addpt(pt)
     pts = QTree.getfrombbox((16, 24, 8, 12))
     ans = [pt for pt in pts if (16 <= pt[0] < 24) and (8 <= pt[1] < 12)]
     pts.sort()
     ans.sort()
     self.assertEqual(pts, ans)
     return
Пример #7
0
 def test_quadtree_add_query(self):
     pts = [(x**0.5,0.5*y**0.875) for x in range(50) for y in range(50)]
     QTree = QuadTree((0, 32, 0, 22))
     for pt in pts:
         QTree.addpt(pt)
     testpts = [(x**0.5,0.5*y**0.875) for (x,y) in zip((3,12,44,23,36),
                                                       (46,42,28,2,13))]
     shouldbetrue = [QTree.querypt(pt) for pt in testpts]
     testpts = [(x**0.5,0.5*y**0.875) for (x,y) in zip((73,12,54,23,63),
                                                       (46,72,28,82,13))]
     shouldbefalse = [QTree.querypt(pt) for pt in testpts]
     self.assertTrue(False not in shouldbetrue)
     self.assertTrue(True not in shouldbefalse)
Пример #8
0
 def test_quadtree_add_query(self):
     pts = [(x**0.5, 0.5 * y**0.875) for x in range(50) for y in range(50)]
     QTree = QuadTree((0, 0, 32, 22))
     for pt in pts:
         QTree.addpt(pt)
     testpts = [(x**0.5, 0.5 * y**0.875)
                for (x, y) in zip((3, 12, 44, 23, 36), (46, 42, 28, 2, 13))]
     shouldbetrue = [QTree.querypt(pt) for pt in testpts]
     testpts = [(x**0.5, 0.5 * y**0.875)
                for (x,
                     y) in zip((73, 12, 54, 23, 63), (46, 72, 28, 82, 13))]
     shouldbefalse = [QTree.querypt(pt) for pt in testpts]
     self.assertTrue(False not in shouldbetrue)
     self.assertTrue(True not in shouldbefalse)
Пример #9
0
 def test_quadtree_construction(self):
     vertices = [(x, x**2) for x in np.linspace(-10, 10, 1000)]
     cs = CoordString(vertices)
     quadtree = QuadTree(cs)
     self.assertEqual(len(quadtree), 1000)
     return