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 == None assert cell.children[0].parent == cell assert cell.children[1].parent == cell
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
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)
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')
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')
def expanding_search(self): """test_larger mesh and different quad trees """ p0 = [2,1] p1 = [4,1] p2 = [4.,4] p3 = [2,4] p4 = [5,4] p5 = [-1,-1] p6 = [1,-1] p7 = [1,1] p8 = [-1,1] points = [p0,p1,p2, p3,p4,p5,p6,p7,p8] # vertices = [[0,1,2],[0,2,3],[1,4,2],[5,6,7], [5,7,8]] mesh = Mesh(points, vertices) # Don't do this, want to control the max and mins #root = build_quadtree(mesh, max_points_per_cell=4) root = Cell(-3, 9, -3, 9, max_points_per_cell = 4) #Insert indices of all vertices root.insert( list(range(mesh.number_of_nodes)) ) #Build quad tree and return root.split() # One point #x = [3.5, 1.5] x = [2.5, 1.5] element_found, sigma0, sigma1, sigma2, k = root.search_fast(x) # One point x = [3.00005, 2.999994] element_found, sigma0, sigma1, sigma2, k = root.search_fast(x) assert element_found is True assert k == 1
def expanding_search(self): """test_larger mesh and different quad trees """ p0 = [2,1] p1 = [4,1] p2 = [4.,4] p3 = [2,4] p4 = [5,4] p5 = [-1,-1] p6 = [1,-1] p7 = [1,1] p8 = [-1,1] points = [p0,p1,p2, p3,p4,p5,p6,p7,p8] # vertices = [[0,1,2],[0,2,3],[1,4,2],[5,6,7], [5,7,8]] mesh = Mesh(points, vertices) # Don't do this, want to control the max and mins #root = build_quadtree(mesh, max_points_per_cell=4) root = Cell(-3, 9, -3, 9, max_points_per_cell = 4) #Insert indices of all vertices root.insert( range(mesh.number_of_nodes) ) #Build quad tree and return root.split() # One point #x = [3.5, 1.5] x = [2.5, 1.5] element_found, sigma0, sigma1, sigma2, k = root.search_fast(x) # One point x = [3.00005, 2.999994] element_found, sigma0, sigma1, sigma2, k = root.search_fast(x) assert element_found is True assert k == 1