def test_mesh_plane_intersection(self): # x-z plane normal = np.array([0., 1., 0.]) sample = np.array([0., 0., 0.]) plane = Plane(sample, normal) # Verify that we're finding the correct number of faces to start with self.assertEqual(len(plane.mesh_intersecting_faces(self.box_mesh)), 8) xsections = plane.mesh_xsections(self.box_mesh) self.assertIsInstance(xsections, list) self.assertEqual(len(xsections), 1) self.assertEqual(len(xsections[0].v), 8) self.assertTrue(xsections[0].closed) self.assertEqual(xsections[0].total_length, 4.0) np.testing.assert_array_equal(xsections[0].v[:, 1], np.zeros((8, ))) for a, b in zip(xsections[0].v[0:-1, [0, 2]], xsections[0].v[1:, [0, 2]]): # Each line changes only one coordinate, and is 0.5 long self.assertEqual(np.sum(a == b), 1) self.assertEqual(np.linalg.norm(a - b), 0.5) xsection = plane.mesh_xsection(self.box_mesh) self.assertEqual(len(xsection.v), 8) self.assertTrue(xsection.closed)
def test_mesh_plane_intersection_with_no_intersection(self): # x-z plane normal = np.array([0., 1., 0.]) sample = np.array([0., 5., 0.]) plane = Plane(sample, normal) # Verify that we're detecting faces that lay entirely in the plane as potential intersections self.assertEqual(len(plane.mesh_intersecting_faces(self.box_mesh)), 0) xsections = plane.mesh_xsections(self.box_mesh) self.assertIsInstance(xsections, list) self.assertEqual(len(xsections), 0) xsection = plane.mesh_xsection(self.box_mesh) self.assertIsNone(xsection.v)