def test_to_from_stl_ascii(): """Test from_stl method with an ascii STL file.""" file_path = 'tests/stl/cube_ascii.stl' mesh = Mesh3D.from_stl(file_path) centroids = [ Point3D(3.33, 0.00, 1.67), Point3D(1.67, 0.00, 3.33), Point3D(5.00, 3.33, 1.67), Point3D(5.00, 1.67, 3.33), Point3D(1.67, 5.00, 1.67), Point3D(3.33, 5.00, 3.33), Point3D(0.00, 1.67, 1.67), Point3D(0.00, 3.33, 3.33), Point3D(1.67, 1.67, 0.00), Point3D(3.33, 3.33, 0.00), Point3D(1.67, 1.67, 5.00), Point3D(3.33, 3.33, 5.00), Point3D(3.33, 0.00, 1.67) ] for count, cent in enumerate(mesh.face_centroids): assert cent.distance_to_point(centroids[count]) <= 0.01 new_folder, new_name = 'tests/stl/', 'cube_ascii_new.stl' new_file = mesh.to_stl(new_folder, new_name) assert os.path.isfile(new_file) Mesh3D.from_stl(new_file) os.remove(new_file)
def test_from_stl_binary(): """Test from_stl method with a binary STL file.""" file_path = 'tests/stl/cube_binary.stl' mesh = Mesh3D.from_stl(file_path) centroids = [ Point3D(3.33, 0.00, 1.67), Point3D(1.67, 0.00, 3.33), Point3D(5.00, 3.33, 1.67), Point3D(5.00, 1.67, 3.33), Point3D(1.67, 5.00, 1.67), Point3D(3.33, 5.00, 3.33), Point3D(0.00, 1.67, 1.67), Point3D(0.00, 3.33, 3.33), Point3D(1.67, 1.67, 0.00), Point3D(3.33, 3.33, 0.00), Point3D(1.67, 1.67, 5.00), Point3D(3.33, 3.33, 5.00) ] for count, cent in enumerate(mesh.face_centroids): assert cent.distance_to_point(centroids[count]) <= 0.01