def test_case_4(self): # build test case 4 polys out_a = (0, 60, 10, 60, 20, 60, 30, 60, 30, 50, 30, 40, 30, 30, 30, 20, 30, 10, 30, 0, 20, 0, 10, 0, 0, 0, 0, 10, 0, 20, 0, 30, 0, 40, 0, 50) in_a1 = (10, 50, 10, 40, 20, 40, 20, 50) in_a2 = (10, 20, 10, 10, 20, 10, 20, 20) outside_poly = self.array_to_vec_pt3d(out_a) inside_polys = (self.array_to_vec_pt3d(in_a1), self.array_to_vec_pt3d(in_a2)) bias = 1.0 poly_input_a = PolyInput(outside_polygon=outside_poly, inside_polygons=inside_polys, bias=bias) out_b = (30, 60, 40, 60, 50, 60, 60, 60, 70, 60, 70, 50, 70, 40, 70, 30, 70, 20, 70, 10, 70, 0, 60, 0, 50, 0, 40, 0, 40, 10, 30, 10, 30, 20, 40, 20, 40, 30, 30, 30, 30, 40, 40, 40, 40, 50, 30, 50) in_b1 = (50, 50, 50, 40, 60, 40, 60, 50) in_b2 = (50, 20, 50, 10, 60, 10, 60, 20) outside_poly_b = self.array_to_vec_pt3d(out_b) inside_polys_b = (self.array_to_vec_pt3d(in_b1), self.array_to_vec_pt3d(in_b2)) bias_b = 1.0 poly_input_b = PolyInput(outside_poly_b, inside_polys_b, bias=bias_b) io = MultiPolyMesherIo(()) io.poly_inputs = (poly_input_a, poly_input_b) # Value Error when file not specified with self.assertRaises(ValueError) as context: mesh_utils.generate_2dm(io, '') self.assertTrue('file_name not specifed. Aborting mesh procedure.' in str(context.exception)) # mesh the polys (success, result) = mesh_utils.generate_2dm(io, "out_file.2dm", 3) self.assertTrue(success) self.assertTrue(os.path.isfile("out_file.2dm")) self.assertFileLinesEqual("../test_files/python/out_file.2dm", "out_file.2dm")
def test_creating_default_PolyInput(self): out_poly = ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0)) pi = PolyInput(out_poly) self.assertIsInstance(pi, PolyInput) self.assertEqual(4, len(pi.outside_polygon)) self.assertEqual(0, len(pi.inside_polygons)) self.assertEqual(1.0, pi.bias) self.assertEqual(None, pi.size_function) self.assertEqual(None, pi.elev_function) self.assertEqual(-1, pi.const_size_bias) self.assertEqual(-1, pi.const_size_function) self.assertEqual(False, pi.remove_internal_four_triangle_pts)
def test_check_for_intersections_4(self): io = MultiPolyMesherIo(()) io.check_topology = True outside_poly1 = ((0, 0, 0), (0, 100, 0), (100, 100, 0), (100, 0, 0)) outside_poly2 = ((10, 10, 0), (10, 110, 0), (110, 110, 0), (110, 10, 0)) poly_input1 = PolyInput(outside_poly1) poly_input2 = PolyInput(outside_poly2) io.poly_inputs = (poly_input1, poly_input2) expected = \ "---Error: Input polygon segments intersect. The segment defined by points 1 and 2 of outer " \ "polygon 0 intersects with the segment defined by points 0 and 1 of outer polygon 1.\n" \ "Error: Input polygon segments intersect. The segment defined by points 2 and 3 of outer " \ "polygon 0 intersects with the segment defined by points 3 and 0 of outer polygon 1.\n" \ "\n\n" (success, errors) = mesh_utils.generate_mesh(io) self.assertEqual(False, success) self.assertEqual(expected, errors)
def test_properties_MultiPolyMesherIo(self): io = MultiPolyMesherIo(()) self.assertIsInstance(io, MultiPolyMesherIo) io.check_topology = True self.assertEqual(True, io.check_topology) io.return_cell_polygons = False self.assertEqual(False, io.return_cell_polygons) points = ((1, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5)) io.points = points self.assertArraysEqual(points, io.points) cells = (1, 5, 9, 13) io.cells = cells self.assertArraysEqual(cells, io.cells) cell_polygons = (2, 4) io.cell_polygons = cell_polygons self.assertArraysEqual(cell_polygons, io.cell_polygons) out_poly = ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0)) pi1 = PolyInput(out_poly) pi1.bias = 2.718 pi2 = PolyInput(out_poly) pi2.bias = 0.618 io.poly_inputs = (pi1, pi2) self.assertTupleStringsEqual((pi1, pi2), io.poly_inputs) rp1 = RefinePoint((5, 0, -3), 3.1, False) rp2 = RefinePoint((-2, -2, 1), -0.4, True) io.refine_points = (rp1, rp2) self.assertTupleStringsEqual((rp1, rp2), io.refine_points)
def test_check_for_intersections(self): io = MultiPolyMesherIo(()) poly_input = PolyInput(outside_polygon=((0, 0, 0), (100, 0, 0), (100, 10, 0), (0, -10, 0))) io.poly_inputs = (poly_input, ) expected = \ "Error: Input polygon segments intersect. The segment defined by points 0 and 1 of outer " \ "polygon 0 intersects with the segment defined by points 2 and 3 of outer polygon 0.\n" (success, errors) = mesh_utils.check_mesh_input_topology(io) self.assertEqual(False, success) self.assertEqual(expected, errors)
def test_repeated_first_and_last(self): # build test case 4 polys out_a = (0, 60, 10, 60, 20, 60, 30, 60, 30, 50, 30, 40, 30, 30, 30, 20, 30, 10, 30, 0, 20, 0, 10, 0, 0, 0, 0, 10, 0, 20, 0, 30, 0, 40, 0, 50, 0, 60) in_a1 = (10, 50, 10, 40, 20, 40, 20, 50, 10, 50) in_a2 = (10, 20, 10, 10, 20, 10, 20, 20, 10, 20) outside_poly = self.array_to_vec_pt3d(out_a) inside_polys = (self.array_to_vec_pt3d(in_a1), self.array_to_vec_pt3d(in_a2)) bias = 1.0 poly_input_a = PolyInput(outside_polygon=outside_poly, inside_polygons=inside_polys, bias=bias) out_b = (30, 60, 40, 60, 50, 60, 60, 60, 70, 60, 70, 50, 70, 40, 70, 30, 70, 20, 70, 10, 70, 0, 60, 0, 50, 0, 40, 0, 40, 10, 30, 10, 30, 20, 40, 20, 40, 30, 30, 30, 30, 40, 40, 40, 40, 50, 30, 50) in_b1 = (50, 50, 50, 40, 60, 40, 60, 50) in_b2 = (50, 20, 50, 10, 60, 10, 60, 20) outside_poly_b = self.array_to_vec_pt3d(out_b) inside_polys_b = (self.array_to_vec_pt3d(in_b1), self.array_to_vec_pt3d(in_b2)) bias_b = 1.0 poly_input_b = PolyInput(outside_poly_b, inside_polys_b, bias=bias_b) io = MultiPolyMesherIo(()) io.poly_inputs = (poly_input_a, poly_input_b) # mesh the polys (success, result) = mesh_utils.generate_2dm(io, "out_file_02_repeated.2dm", 3) self.assertTrue(success) self.assertTrue(os.path.isfile("out_file_02_repeated.2dm")) self.assertFileLinesEqual("../test_files/python/out_file.2dm", "out_file_02_repeated.2dm")
def test_check_for_intersections_2(self): io = MultiPolyMesherIo(()) io.check_topology = True outside_poly = ((0, 0, 0), (100, 0, 0), (100, 100, 0), (0, 100, 0)) inside_polys = (((10, 50, 0), (90, 50, 0), (90, 90, 0), (10, 10, 0)), ) poly_input = PolyInput(outside_poly, inside_polys) io.poly_inputs = (poly_input, ) expected = \ "---Error: Input polygon segments intersect. The segment defined by points 0 and 1 of inner " \ "polygon 0 of outer polygon 0 intersects with the segment defined by points 2 and 3 of inner " \ "polygon 0 of outer polygon 0.\n" \ "\n\n" (success, errors) = mesh_utils.generate_mesh(io) self.assertEqual(False, success) self.assertEqual(expected, errors)
def test_simple_polygon(self): outside_poly = [(0, 10, 0), (0, 20, 0), (0, 30, 0), (0, 40, 0), (0, 50, 0), (0, 60, 0), (0, 70, 0), (0, 80, 0), (0, 90, 0), (0, 100, 0), (10, 100, 0), (20, 100, 0), (30, 100, 0), (40, 100, 0), (50, 100, 0), (60, 100, 0), (70, 100, 0), (80, 100, 0), (90, 100, 0), (100, 100, 0), (100, 90, 0), (100, 80, 0), (100, 70, 0), (100, 60, 0), (100, 50, 0), (100, 40, 0), (100, 30, 0), (100, 20, 0), (100, 10, 0), (100, 0, 0), (90, 0, 0), (80, 0, 0), (70, 0, 0), (60, 0, 0), (50, 0, 0), (40, 0, 0), (30, 0, 0), (20, 0, 0), (10, 0, 0), (0, 0, 0)] inside_polys = [[(40, 40, 0), (50, 40, 0), (60, 40, 0), (60, 50, 0), (60, 60, 0), (50, 60, 0), (40, 60, 0), (40, 50, 0)]] input_poly = PolyInput(outside_poly, inside_polys) input = MultiPolyMesherIo(()) input.poly_inputs = [input_poly] status, error = mesh_utils.generate_mesh(input) self.assertEqual(139, len(input.points)) self.assertEqual(1150, len(input.cells)) self.assertTrue(status) self.assertEqual(error, '')
def test_creating_PolyInput(self): outside_poly = ((1, 2, 0), (5, 2, 0), (5, 9, 0), (1, 9, 0)) inside_polys = (((3, 3, 0), (2.5, 4, 0), (2, 3, 0)), ((4, 8, 0), (3, 7, 0), (2, 8, 0))) poly_corners = (0, 1, 2, 3) bias = 3.14159 pts = ((1, 0, 0), (10, 0, 0), (10, 10, 0)) size_func = InterpLinear(pts) elev_func = InterpIdw(pts) pi = PolyInput(outside_polygon=outside_poly, inside_polygons=inside_polys, bias=bias, size_function=size_func, patch_polygon_corners=poly_corners, elev_function=elev_func) self.assertIsInstance(pi, PolyInput) self.assertArraysEqual(outside_poly, pi.outside_polygon) self.assertInsidePolysEqual(inside_polys, pi.inside_polygons) self.assertEqual(bias, pi.bias) self.assertEqual(size_func.to_string(), pi.size_function.to_string()) self.assertEqual(elev_func.to_string(), pi.elev_function.to_string()) self.assertEqual(-1, pi.const_size_bias) self.assertEqual(-1, pi.const_size_function) self.assertEqual(False, pi.remove_internal_four_triangle_pts)
def test_properties_PolyInput(self): out_poly = ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0)) pi = PolyInput(out_poly) outside_poly = ((1, 2, 0), (5, 2, 0), (5, 9, 0), (1, 9, 0)) inside_polys = (((3, 3, 0), (2.5, 4, 0), (2, 3, 0)), ((4, 8, 0), (3, 7, 0), (2, 8, 0))) poly_corners = (0, 1, 2, 3) pts = ((1, 2, 3), (4, 5, 6), (0, 5, 7)) size_func = InterpLinear(pts) elev_func = InterpIdw(pts) seed_points = ((3, 3, 0), (4, 3, 0), (4, 8, 0), (3, 8, 0)) relaxation_method = "spring_relaxation" self.assertEqual(4, len(pi.outside_polygon)) pi.outside_polygon = outside_poly self.assertArraysEqual(outside_poly, pi.outside_polygon) self.assertEqual(0, len(pi.inside_polygons)) pi.inside_polygons = inside_polys self.assertInsidePolysEqual(inside_polys, pi.inside_polygons) self.assertEqual(0, len(pi.patch_polygon_corners)) pi.patch_polygon_corners = poly_corners self.assertArraysEqual(poly_corners, pi.patch_polygon_corners) self.assertEqual(1.0, pi.bias) pi.bias = 0.3 self.assertEqual(0.3, pi.bias) self.assertEqual(None, pi.size_function) pi.size_function = size_func self.assertEqual(size_func.to_string(), pi.size_function.to_string()) self.assertEqual(None, pi.elev_function) pi.elev_function = elev_func self.assertEqual(elev_func.to_string(), pi.elev_function.to_string()) self.assertEqual(-1, pi.const_size_bias) pi.const_size_bias = 4.0 self.assertEqual(4.0, pi.const_size_bias) self.assertEqual(-1, pi.const_size_function) pi.const_size_function = 1.2 self.assertEqual(1.2, pi.const_size_function) self.assertEqual(False, pi.remove_internal_four_triangle_pts) pi.remove_internal_four_triangle_pts = True self.assertEqual(True, pi.remove_internal_four_triangle_pts) self.assertEqual(0, len(pi.seed_points)) pi.seed_points = seed_points self.assertArraysEqual(seed_points, pi.seed_points) self.assertEqual("", pi.relaxation_method) pi.relaxation_method = relaxation_method self.assertEqual(relaxation_method, pi.relaxation_method)