|
7 | 7 | tolerance = 1e-6
|
8 | 8 |
|
9 | 9 |
|
| 10 | +def close(a, b): |
| 11 | + return numpy.allclose(a, b, atol=tolerance) |
| 12 | + |
| 13 | + |
10 | 14 | def test_mass_properties_for_half_donut(binary_ascii_path, speedups):
|
11 |
| - """ |
| 15 | + ''' |
12 | 16 | Checks the results of method get_mass_properties() on
|
13 | 17 | STL ASCII and binary files HalfDonut.stl
|
14 | 18 | One checks the results obtained with stl
|
15 | 19 | with the ones obtained with meshlab
|
16 |
| - """ |
| 20 | + ''' |
17 | 21 | filename = binary_ascii_path.join('HalfDonut.stl')
|
18 | 22 | mesh = stl.StlMesh(str(filename), speedups=speedups)
|
19 | 23 | volume, cog, inertia = mesh.get_mass_properties()
|
20 |
| - assert(abs(volume - 2.343149) < tolerance) |
21 |
| - assert(numpy.allclose(cog, |
22 |
| - numpy.array([1.500001, 0.209472, 1.500001]), |
23 |
| - atol=tolerance)) |
24 |
| - assert(numpy.allclose(inertia, |
25 |
| - numpy.array([[+1.390429, +0.000000, +0.000000], |
26 |
| - [+0.000000, +2.701025, +0.000000], |
27 |
| - [+0.000000, +0.000000, +1.390429]]), |
28 |
| - atol=tolerance)) |
| 24 | + assert close([volume], [2.343149]) |
| 25 | + assert close(cog, [1.500001, 0.209472, 1.500001]) |
| 26 | + assert close(inertia, [[+1.390429, +0.000000, +0.000000], |
| 27 | + [+0.000000, +2.701025, +0.000000], |
| 28 | + [+0.000000, +0.000000, +1.390429]]) |
29 | 29 |
|
30 | 30 |
|
31 | 31 | def test_mass_properties_for_moon(binary_ascii_path, speedups):
|
32 |
| - """ |
| 32 | + ''' |
33 | 33 | Checks the results of method get_mass_properties() on
|
34 | 34 | STL ASCII and binary files Moon.stl
|
35 | 35 | One checks the results obtained with stl
|
36 | 36 | with the ones obtained with meshlab
|
37 |
| - """ |
| 37 | + ''' |
38 | 38 | filename = binary_ascii_path.join('Moon.stl')
|
39 | 39 | mesh = stl.StlMesh(str(filename), speedups=speedups)
|
40 | 40 | volume, cog, inertia = mesh.get_mass_properties()
|
41 |
| - assert(abs(volume - 0.888723) < tolerance) |
42 |
| - assert(numpy.allclose(cog, |
43 |
| - numpy.array([0.906913, 0.170731, 1.500001]), |
44 |
| - atol=tolerance)) |
45 |
| - assert(numpy.allclose(inertia, |
46 |
| - numpy.array([[+0.562097, -0.000457, +0.000000], |
47 |
| - [-0.000457, +0.656851, +0.000000], |
48 |
| - [+0.000000, +0.000000, +0.112465]]), |
49 |
| - atol=tolerance)) |
| 41 | + assert close([volume], [0.888723]) |
| 42 | + assert close(cog, [0.906913, 0.170731, 1.500001]) |
| 43 | + assert close(inertia, [[+0.562097, -0.000457, +0.000000], |
| 44 | + [-0.000457, +0.656851, +0.000000], |
| 45 | + [+0.000000, +0.000000, +0.112465]]) |
50 | 46 |
|
51 | 47 |
|
52 | 48 | @pytest.mark.parametrize('filename', ('Star.stl', 'StarWithEmptyHeader.stl'))
|
53 | 49 | def test_mass_properties_for_star(binary_ascii_path, filename, speedups):
|
54 |
| - """ |
| 50 | + ''' |
55 | 51 | Checks the results of method get_mass_properties() on
|
56 | 52 | STL ASCII and binary files Star.stl and
|
57 | 53 | STL binary file StarWithEmptyHeader.stl (with no header)
|
58 | 54 | One checks the results obtained with stl
|
59 | 55 | with the ones obtained with meshlab
|
60 |
| - """ |
| 56 | + ''' |
61 | 57 | filename = binary_ascii_path.join(filename)
|
62 | 58 | if not filename.exists():
|
63 | 59 | pytest.skip('STL file does not exist')
|
64 | 60 | mesh = stl.StlMesh(str(filename), speedups=speedups)
|
65 | 61 | volume, cog, inertia = mesh.get_mass_properties()
|
66 |
| - assert(abs(volume - 1.416599) < tolerance) |
67 |
| - assert(numpy.allclose(cog, |
68 |
| - numpy.array([1.299040, 0.170197, 1.499999]), |
69 |
| - atol=tolerance)) |
70 |
| - assert(numpy.allclose(inertia, |
71 |
| - numpy.array([[+0.509549, +0.000000, -0.000000], |
72 |
| - [+0.000000, +0.991236, +0.000000], |
73 |
| - [-0.000000, +0.000000, +0.509550]]), |
74 |
| - atol=tolerance)) |
| 62 | + assert close([volume], [1.416599]) |
| 63 | + assert close(cog, [1.299040, 0.170197, 1.499999]) |
| 64 | + assert close(inertia, [[+0.509549, +0.000000, -0.000000], |
| 65 | + [+0.000000, +0.991236, +0.000000], |
| 66 | + [-0.000000, +0.000000, +0.509550]]) |
| 67 | + |
| 68 | + |
| 69 | +def test_mass_properties_for_half_donut_with_density( |
| 70 | + binary_ascii_path, speedups): |
| 71 | + ''' |
| 72 | + Checks the results of method get_mass_properties_with_density() on |
| 73 | + STL ASCII and binary files HalfDonut.stl |
| 74 | + One checks the results obtained with stl |
| 75 | + with the ones obtained with meshlab |
| 76 | + ''' |
| 77 | + filename = binary_ascii_path.join('HalfDonut.stl') |
| 78 | + mesh = stl.StlMesh(str(filename), speedups=speedups) |
| 79 | + volume, mass, cog, inertia = mesh.get_mass_properties_with_density(1.23) |
| 80 | + |
| 81 | + assert close([mass], [2.882083302268982]) |
| 82 | + assert close([volume], [2.343149026234945]) |
| 83 | + assert close(cog, [1.500001, 0.209472, 1.500001]) |
| 84 | + print('inertia') |
| 85 | + numpy.set_printoptions(suppress=True) |
| 86 | + print(inertia) |
| 87 | + assert close(inertia, [[+1.71022851, +0.00000001, -0.00000011], |
| 88 | + [+0.00000001, +3.32226227, +0.00000002], |
| 89 | + [-0.00000011, +0.00000002, +1.71022859]]) |
0 commit comments