def test_build_quadtree(self): a = [3, 7] b = [5, 7] c = [5, 5] d = [7, 7] e = [15, 15] f = [15, 30] g = [30, 10] h = [30, 30] points = [a, b, c, d, e, f, g, h] #bac, bce, ecf, dbe, daf, dae vertices = [[1,0,2], [1,3,4], [1,2,3], [5,4,7], [4,6,7]] mesh = Mesh(points, vertices) Q = MeshQuadtree(mesh) #Q.show() #print Q.count() self.assertEqual(Q.count(), len(vertices)) # test a point that falls within a triangle result = Q.search([10, 10]) assert isinstance(result, (list, tuple)), 'should be a list'
def test_underlying_function(self): """test_larger mesh and different quad trees """ return points, vertices, boundary = rectangular(2, 2, 1, 1) mesh = Mesh(points, vertices, boundary) root = MeshQuadtree(mesh) root.set_last_triangle() # One point x = ensure_numeric([0.5, 0.5]) found, sigma0, sigma1, sigma2, k = \ root._search_triangles_of_vertices(root.search(x), x) if k >= 0: V = mesh.get_vertex_coordinates(k) # nodes for triangle k assert is_inside_polygon(x, V) assert found is True else: assert found is False # More points for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7], [0.1,0.9], [0.4,0.6], [0.9,0.1], [10, 3]]: triangles = root.search(x) #print x, candidate_vertices found, sigma0, sigma1, sigma2, k = \ root._search_triangles_of_vertices(triangles, ensure_numeric(x)) if k >= 0: V = mesh.get_vertex_coordinates(k) # nodes for triangle k assert is_inside_polygon(x, V) assert found is True else: assert found is False
def test_underlying_function(self): """test_larger mesh and different quad trees """ return points, vertices, boundary = rectangular(2, 2, 1, 1) mesh = Mesh(points, vertices, boundary) root = MeshQuadtree(mesh) root.set_last_triangle() # One point x = ensure_numeric([0.5, 0.5]) found, sigma0, sigma1, sigma2, k = \ root._search_triangles_of_vertices(root.search(x), x) if k >= 0: V = mesh.get_vertex_coordinates(k) # nodes for triangle k assert is_inside_polygon(x, V) assert found is True else: assert found is False # More points for x in [[0.6, 0.3], [0.1, 0.2], [0.7,0.7], [0.1,0.9], [0.4,0.6], [0.9,0.1], [10, 3]]: triangles = root.search(x) #print x, candidate_vertices found, sigma0, sigma1, sigma2, k = \ root._search_triangles_of_vertices(triangles, ensure_numeric(x)) if k >= 0: V = mesh.get_vertex_coordinates(k) # nodes for triangle k assert is_inside_polygon(x, V) assert found is True else: assert found is False
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])