| 9 | internal class BooleanTests |
| 10 | { |
| 11 | [Test] |
| 12 | public void TestOperations() |
| 13 | { |
| 14 | const float PI = 3.14159265f; |
| 15 | Mesh meshA = makeTorus(1.1f, 0.5f, 8, 8); |
| 16 | Mesh meshB = makeTorus(1.0f, 0.2f, 8, 8); |
| 17 | meshB.transform( AffineXf3f.linear( Matrix3f.rotation( Vector3f.plusZ(), Vector3f.plusY() ) ) ); |
| 18 | |
| 19 | const float shiftStep = 0.2f; |
| 20 | const float angleStep = PI; |
| 21 | var baseAxis = new Vector3f[] { Vector3f.plusX(), Vector3f.plusY(), Vector3f.plusZ() }; |
| 22 | |
| 23 | for (int maskTrans = 0; maskTrans < 8; ++maskTrans) |
| 24 | { |
| 25 | for (int maskRot = 0; maskRot < 8; ++maskRot) |
| 26 | { |
| 27 | for (float shift = 0.01f; shift < 0.2f; shift += shiftStep) |
| 28 | { |
| 29 | Vector3f shiftVec = new Vector3f(); |
| 30 | for (int i = 0; i < 3; ++i) |
| 31 | if ( ( maskTrans & ( 1 << i ) ) > 0 ) |
| 32 | shiftVec += shift * baseAxis[i]; |
| 33 | |
| 34 | for (float angle = PI * 0.01f; angle < PI * 7.0f / 18.0f; angle += angleStep) |
| 35 | { |
| 36 | Matrix3f rotation = new Matrix3f(); |
| 37 | for (int i = 0; i < 3; ++i) |
| 38 | if ( ( maskRot & (1 << i) ) > 0 ) |
| 39 | rotation = Matrix3f.rotation( baseAxis[i], angle ) * rotation; |
| 40 | |
| 41 | BooleanParameters parameters = new BooleanParameters(); |
| 42 | parameters.rigidB2A = AffineXf3f.translation(shiftVec) * AffineXf3f.linear(rotation); |
| 43 | |
| 44 | Assert.DoesNotThrow(() => boolean(meshA, meshB, BooleanOperation.Union, parameters)); |
| 45 | Assert.DoesNotThrow(() => boolean(meshA, meshB, BooleanOperation.Intersection, parameters)); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | [Test] |
| 53 | public void TestMapper() |