Example #1
0
    def test_get_siblings(self):
        """ Make sure children know their parent. """
        cell = Cell(AABB(0, 10, 0, 5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), 222)])

        assert len(cell.children) == 2
        assert cell.parent is None
        assert cell.children[0].parent == cell
        assert cell.children[1].parent == cell
Example #2
0
    def test_add_data(self):
        """ Test add and retrieve arbitrary data from tree structure. """
        cell = Cell(AABB(0, 10, 0, 5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), 222),  \
                     (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])

        result = cell.retrieve()
        assert isinstance(result, (list, tuple)), 'should be a list'

        self.assertEqual(len(result), 4)
Example #3
0
    def test_search(self):
        """ Test search tree for an intersection. """
        test_tag = 222
        cell = Cell(AABB(0, 10, 0, 5), None)
        cell.insert([(AABB(1, 3, 1, 3), 111), (AABB(8, 9, 1, 2), test_tag),  \
                     (AABB(7, 8, 3, 4), 333), (AABB(1, 10, 0, 1), 444)])

        result = cell.search([8.5, 1.5])
        assert isinstance(result, (list, tuple)), 'should be a list'
        assert (len(result) == 1)
        data, _ = result[0]
        self.assertEqual(data, test_tag, 'only 1 point should intersect')
Example #4
0
 def test_aabb_contains(self):
     """ Test if point is correctly classified as falling inside or
         outside of bounding box. """
     box = AABB(1, 21, 1, 11)
     assert box.contains([10, 5])
     assert box.contains([1, 1])
     assert box.contains([20, 6])
     assert not box.contains([-1, -1])
     assert not box.contains([5, 70])
     assert not box.contains([6, -70])
     assert not box.contains([-1, 6])
     assert not box.contains([50, 6])
    def test_aabb_split_horiz(self):
        """ Test that a bounding box will be split along the horizontal axis
        correctly. """
        parent = AABB(1, 11, 1, 41)
        
        child1, child2 = parent.split(0.6)

        self.assertEqual(child1.xmin, 1)
        self.assertEqual(child1.xmax, 11)
        self.assertEqual(child1.ymin, 1)
        self.assertEqual(child1.ymax, 25)
        
        self.assertEqual(child2.xmin, 1)
        self.assertEqual(child2.xmax, 11)
        self.assertEqual(child2.ymin, 17)
        self.assertEqual(child2.ymax, 41)          
    def test_aabb_split_vert(self):
        """ Test that a bounding box can be split correctly along an axis.
        """
        parent = AABB(1, 21, 1, 11)
        
        child1, child2 = parent.split(0.6)

        self.assertEqual(child1.xmin, 1)
        self.assertEqual(child1.xmax, 13)
        self.assertEqual(child1.ymin, 1)
        self.assertEqual(child1.ymax, 11)
        
        self.assertEqual(child2.xmin, 9)
        self.assertEqual(child2.xmax, 21)
        self.assertEqual(child2.ymin, 1)
        self.assertEqual(child2.ymax, 11)    
Example #7
0
    def test_aabb_split_horiz(self):
        """ Test that a bounding box will be split along the horizontal axis
        correctly. """
        parent = AABB(1, 11, 1, 41)

        child1, child2 = parent.split(0.6)

        self.assertEqual(child1.xmin, 1)
        self.assertEqual(child1.xmax, 11)
        self.assertEqual(child1.ymin, 1)
        self.assertEqual(child1.ymax, 25)

        self.assertEqual(child2.xmin, 1)
        self.assertEqual(child2.xmax, 11)
        self.assertEqual(child2.ymin, 17)
        self.assertEqual(child2.ymax, 41)
Example #8
0
    def test_aabb_split_vert(self):
        """ Test that a bounding box can be split correctly along an axis.
        """
        parent = AABB(1, 21, 1, 11)

        child1, child2 = parent.split(0.6)

        self.assertEqual(child1.xmin, 1)
        self.assertEqual(child1.xmax, 13)
        self.assertEqual(child1.ymin, 1)
        self.assertEqual(child1.ymax, 11)

        self.assertEqual(child2.xmin, 9)
        self.assertEqual(child2.xmax, 21)
        self.assertEqual(child2.ymin, 1)
        self.assertEqual(child2.ymax, 11)
 def test_aabb_contains(self):
     """ Test if point is correctly classified as falling inside or
         outside of bounding box. """
     box = AABB(1, 21, 1, 11)
     assert box.contains([10, 5])
     assert box.contains([1, 1])
     assert box.contains([20, 6])
     assert not box.contains([-1, -1])
     assert not box.contains([5, 70])
     assert not box.contains([6, -70])
     assert not box.contains([-1, 6])
     assert not box.contains([50, 6])        
Example #10
0
    def test_build_quadtreeII(self):

        self.cell = Cell(AABB(100, 140, 0, 40), 'cell')

        p0 = [34.6292076111,-7999.92529297]
        p1 = [8000.0, 7999.0]
        p2 = [-7999.96630859, 7999.0]
        p3 = [34, 7999.97021484]

        points = [p0,p1,p2, p3]
        #bac, bce, ecf, dbe, daf, dae
        vertices = [[0,1,2],[0,3,2]]

        mesh = Mesh(points, vertices)

        #This was causing round off error
        Q = MeshQuadtree(mesh)
Example #11
0
    def test_retrieve_triangles(self):

        cell = Cell(AABB(0, 6, 0, 6), 'cell')

        p0 = [2,1]
        p1 = [4,1]
        p2 = [4.,4]
        p3 = [2,4]
        p4 = [5,4]

        points = [p0,p1,p2, p3, p4]
        #
        vertices = [[0,1,2],[0,2,3],[1,4,2]]

        mesh = Mesh(points, vertices)

        Q = MeshQuadtree(mesh)
        results = Q.search([4.5, 3])
Example #12
0
 def set_extents(self):
     extents = AABB(*self.mesh.get_extent(absolute=True))
     extents.grow(1.001)  # To avoid round off error
     numextents = [extents.xmin, extents.xmax, extents.ymin, extents.ymax]
     self.extents = num.array(numextents, num.float)
 def set_extents(self):
     extents = AABB(*self.mesh.get_extent(absolute=True))
     extents.grow(1.001)  # To avoid round off error
     numextents = [extents.xmin, extents.xmax, extents.ymin, extents.ymax]
     self.extents = num.array(numextents, num.float)