|
| 1 | +import tempfile |
| 2 | + |
| 3 | +try: |
| 4 | + from . import common as c |
| 5 | +except BaseException: |
| 6 | + import common as c |
| 7 | + |
| 8 | + |
| 9 | +class IGESExportTest(c.unittest.TestCase): |
| 10 | + def test_iges_round_trip_bsplines(self): |
| 11 | + """ |
| 12 | + Test npz export-import routine |
| 13 | + """ |
| 14 | + bsp_el2 = c.splinepy.BSpline( |
| 15 | + degrees=[1, 1], |
| 16 | + control_points=[[0, 1], [1, 1], [0, 2], [1, 2]], |
| 17 | + knot_vectors=[[0, 0, 1, 1], [0, 0, 1, 1]], |
| 18 | + ) |
| 19 | + nur_el3 = c.splinepy.NURBS( |
| 20 | + degrees=[1, 1], |
| 21 | + control_points=[[1, 1], [2, 1], [1, 2], [2, 2]], |
| 22 | + weights=[1, 1, 1, 1], |
| 23 | + knot_vectors=[[0, 0, 1, 1], [0, 0, 1, 1]], |
| 24 | + ) |
| 25 | + |
| 26 | + # Make it more tricky |
| 27 | + bsp_el2.elevate_degrees(0) |
| 28 | + bsp_el2.elevate_degrees(1) |
| 29 | + nur_el3.elevate_degrees(0) |
| 30 | + nur_el3.elevate_degrees(1) |
| 31 | + bsp_el2.insert_knots(1, [0.5]) |
| 32 | + nur_el3.insert_knots(1, [0.5]) |
| 33 | + |
| 34 | + # Test output against input |
| 35 | + list_of_splines = [bsp_el2, nur_el3] |
| 36 | + with tempfile.TemporaryDirectory() as tmpd: |
| 37 | + tmpf = c.to_tmpf(tmpd) |
| 38 | + c.splinepy.io.iges.export(tmpf, list_of_splines) |
| 39 | + list_of_splines_loaded = c.splinepy.io.iges.load(tmpf) |
| 40 | + |
| 41 | + # to compare we need 3d "bumped" splines of originals |
| 42 | + splines_in_3d = [] |
| 43 | + for s in list_of_splines: |
| 44 | + tmp_s = s.copy() |
| 45 | + tmp_s.cps = c.np.hstack( |
| 46 | + [tmp_s.cps, c.np.zeros((len(tmp_s.cps), 1))] |
| 47 | + ) |
| 48 | + splines_in_3d.append(tmp_s) |
| 49 | + |
| 50 | + assert all( |
| 51 | + c.are_splines_equal(a, b) |
| 52 | + for a, b in zip(splines_in_3d, list_of_splines_loaded) |
| 53 | + ) |
| 54 | + |
| 55 | + |
| 56 | +if __name__ == "__main__": |
| 57 | + c.unittest.main() |
0 commit comments