public unsafe void TestMeshColliderCreateWithInvalidIndices() { int numTriangles = 10; var vertices = new NativeArray <float3>(numTriangles * 3, Allocator.Persistent); var triangles = new NativeArray <int>(numTriangles * 3, Allocator.Persistent); for (int i = 0; i < numTriangles * 3; i++) { vertices[i] = new float3((float)i, 1.0f * (float)(i % 2), (float)(i + 1)); triangles[i] = i; } Random rnd = new Random(0x12345678); for (int i = 0; i < 100; i++) { int indexToChange = rnd.NextInt(0, triangles.Length - 1); int invalidValue = rnd.NextInt() * (rnd.NextBool() ? -1 : 1); triangles[indexToChange] = invalidValue; TestUtils.ThrowsException <System.ArgumentException>( () => Unity.Physics.MeshCollider.Create(vertices, triangles) ); triangles[indexToChange] = indexToChange; } triangles.Dispose(); vertices.Dispose(); }
public void TestSphereColliderCreateInvalid() { var sphere = new SphereGeometry { Center = new float3(-10.34f, 0.0f, -1.54f), Radius = 1.25f }; // positive inf center { var invalidSphere = sphere; invalidSphere.Center = new float3(float.PositiveInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere)); } // negative inf center { var invalidSphere = sphere; invalidSphere.Center = new float3(float.NegativeInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere)); } // nan center { var invalidSphere = sphere; invalidSphere.Center = new float3(float.NaN, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere)); } // negative radius { var invalidSphere = sphere; invalidSphere.Radius = -0.5f; TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere)); } // positive inf radius { var invalidSphere = sphere; invalidSphere.Radius = float.PositiveInfinity; TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere)); } // negative inf radius { var invalidSphere = sphere; invalidSphere.Radius = float.NegativeInfinity; TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere)); } // nan radius { var invalidSphere = sphere; invalidSphere.Radius = float.NaN; TestUtils.ThrowsException <System.ArgumentException>(() => SphereCollider.Create(invalidSphere)); } }
public unsafe void TestMeshColliderCreateWithInvalidIndices() { int numTriangles = 10; var vertices = new NativeArray <float3>(numTriangles * 3, Allocator.Persistent); var triangles = new NativeArray <int3>(numTriangles, Allocator.Persistent); for (int i = 0; i < numTriangles; i++) { int firstVertexIndex = i * 3; vertices[firstVertexIndex] = new float3((float)firstVertexIndex, 1.0f * (float)(firstVertexIndex % 2), (float)(firstVertexIndex + 1)); vertices[firstVertexIndex + 1] = new float3((float)(firstVertexIndex + 1), 1.0f * (float)((firstVertexIndex + 1) % 2), (float)(firstVertexIndex + 2)); vertices[firstVertexIndex + 2] = new float3((float)(firstVertexIndex + 2), 1.0f * (float)((firstVertexIndex + 2) % 2), (float)(firstVertexIndex + 3)); triangles[i] = new int3(firstVertexIndex, firstVertexIndex + 1, firstVertexIndex + 2); } Random rnd = new Random(0x12345678); for (int i = 0; i < 100; i++) { int indexToChange = rnd.NextInt(0, triangles.Length * 3 - 1); int triangleIndex = indexToChange / 3; int vertexInTriangle = indexToChange % 3; int invalidValue = rnd.NextInt() * (rnd.NextBool() ? -1 : 1); var triangle = triangles[triangleIndex]; triangle[vertexInTriangle] = invalidValue; triangles[triangleIndex] = triangle; TestUtils.ThrowsException <System.ArgumentException>( () => Unity.Physics.MeshCollider.Create(vertices, triangles) ); triangle[vertexInTriangle] = indexToChange; triangles[triangleIndex] = triangle; } triangles.Dispose(); vertices.Dispose(); }
public void TestBoxColliderCreateInvalid() { float3 center = new float3(1.0f, 0.0f, 0.0f); quaternion orientation = quaternion.AxisAngle(math.normalize(new float3(4.3f, 1.2f, 0.1f)), 1085.0f); float3 size = new float3(1.0f, 2.0f, 3.0f); float convexRadius = 0.45f; // Invalid center, positive infinity { float3 invalidCenter = new float3(float.PositiveInfinity, 1.0f, 1.0f); TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(invalidCenter, orientation, size, convexRadius) ); } // Invalid center, positive infinity { float3 invalidCenter = new float3(float.NegativeInfinity, 1.0f, 1.0f); TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(invalidCenter, orientation, size, convexRadius) ); } // Invalid center, nan { float3 invalidCenter = new float3(float.NaN, 1.0f, 1.0f); TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(invalidCenter, orientation, size, convexRadius) ); } // Negative size { float3 invalidSize = new float3(-1.0f, 1.0f, 1.0f); TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(center, orientation, invalidSize, convexRadius) ); } // Invalid size, positive inf { float3 invalidSize = new float3(float.PositiveInfinity, 1.0f, 1.0f); TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(center, orientation, invalidSize, convexRadius) ); } // Invalid size, negative inf { float3 invalidSize = new float3(float.NegativeInfinity, 1.0f, 1.0f); TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(center, orientation, invalidSize, convexRadius) ); } // Invalid size, nan { float3 invalidSize = new float3(float.NaN, 1.0f, 1.0f); TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(center, orientation, invalidSize, convexRadius) ); } // Negative convex radius { float invalidConvexRadius = -0.0001f; TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(center, orientation, size, invalidConvexRadius) ); } // Invalid convex radius, +inf { float invalidConvexRadius = float.PositiveInfinity; TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(center, orientation, size, invalidConvexRadius) ); } // Invalid convex radius, -inf { float invalidConvexRadius = float.NegativeInfinity; TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(center, orientation, size, invalidConvexRadius) ); } // Invalid convex radius, nan { float invalidConvexRadius = float.NaN; TestUtils.ThrowsException <System.ArgumentException>( () => BoxCollider.Create(center, orientation, size, invalidConvexRadius) ); } }
public void TestConvexColliderCreateInvalid() { // Invalid points { float convexRadius = 0.15f; // invalid point, +inf { var invalidPoints = new NativeArray <float3>(6, Allocator.Temp) { [0] = new float3(1.45f, 8.67f, 3.45f), [1] = new float3(8.75f, 1.23f, 6.44f), [2] = new float3(float.PositiveInfinity, 5.33f, -2.55f), [3] = new float3(8.76f, 4.56f, -4.54f), [4] = new float3(9.75f, -0.45f, -8.99f), [5] = new float3(7.66f, 3.44f, 0.0f) }; TestUtils.ThrowsException <System.ArgumentException>( () => ConvexCollider.Create(invalidPoints, convexRadius) ); invalidPoints.Dispose(); } // invalid point, -inf { var invalidPoints = new NativeArray <float3>(6, Allocator.Temp) { [0] = new float3(1.45f, 8.67f, 3.45f), [1] = new float3(8.75f, 1.23f, 6.44f), [2] = new float3(float.NegativeInfinity, 5.33f, -2.55f), [3] = new float3(8.76f, 4.56f, -4.54f), [4] = new float3(9.75f, -0.45f, -8.99f), [5] = new float3(7.66f, 3.44f, 0.0f), }; TestUtils.ThrowsException <System.ArgumentException>( () => ConvexCollider.Create(invalidPoints, convexRadius) ); invalidPoints.Dispose(); } // invalid point, NaN { var invalidPoints = new NativeArray <float3>(6, Allocator.Temp) { [0] = new float3(1.45f, 8.67f, 3.45f), [1] = new float3(8.75f, 1.23f, 6.44f), [2] = new float3(float.NaN, 5.33f, -2.55f), [3] = new float3(8.76f, 4.56f, -4.54f), [4] = new float3(9.75f, -0.45f, -8.99f), [5] = new float3(7.66f, 3.44f, 0.0f) }; TestUtils.ThrowsException <System.ArgumentException>( () => ConvexCollider.Create(invalidPoints, convexRadius) ); invalidPoints.Dispose(); } } // invalid convex radius { var points = new NativeArray <float3>(6, Allocator.Temp) { [0] = new float3(1.45f, 8.67f, 3.45f), [1] = new float3(8.75f, 1.23f, 6.44f), [2] = new float3(7.54f, 5.33f, -2.55f), [3] = new float3(8.76f, 4.56f, -4.54f), [4] = new float3(9.75f, -0.45f, -8.99f), [5] = new float3(7.66f, 3.44f, 0.0f) }; float3 scale = new float3(1.0f, 1.0f, 1.0f); // negative convex radius { float invalidConvexRadius = -0.30f; TestUtils.ThrowsException <System.ArgumentException>( () => ConvexCollider.Create(points, invalidConvexRadius) ); } // +inf convex radius { float invalidConvexRadius = float.PositiveInfinity; TestUtils.ThrowsException <System.ArgumentException>( () => ConvexCollider.Create(points, invalidConvexRadius) ); } // -inf convex radius { float invalidConvexRadius = float.NegativeInfinity; TestUtils.ThrowsException <System.ArgumentException>( () => ConvexCollider.Create(points, invalidConvexRadius) ); } // nan convex radius { float invalidConvexRadius = float.NaN; TestUtils.ThrowsException <System.ArgumentException>( () => ConvexCollider.Create(points, invalidConvexRadius) ); } points.Dispose(); } }
public void TestCreateInvalid() { // +inf vertex { float3[] vertices = { new float3(-4.5f, float.PositiveInfinity, 1.0f), new float3(3.4f, 2.7f, 1.0f), new float3(3.4f, 0.7f, 1.0f), new float3(-3.4f, 1.2f, 1.1f) }; TestUtils.ThrowsException <System.ArgumentException>( () => PolygonCollider.CreateTriangle(vertices[0], vertices[1], vertices[2]) ); TestUtils.ThrowsException <System.ArgumentException>( () => PolygonCollider.CreateQuad(vertices[0], vertices[1], vertices[2], vertices[3]) ); } // -inf vertex { float3[] vertices = { new float3(-4.5f, float.NegativeInfinity, 1.0f), new float3(3.4f, 2.7f, 1.0f), new float3(3.4f, 0.7f, 1.0f), new float3(-3.4f, 1.2f, 1.1f) }; TestUtils.ThrowsException <System.ArgumentException>( () => PolygonCollider.CreateTriangle(vertices[0], vertices[1], vertices[2]) ); TestUtils.ThrowsException <System.ArgumentException>( () => PolygonCollider.CreateQuad(vertices[0], vertices[1], vertices[2], vertices[3]) ); } // nan vertex { float3[] vertices = { new float3(-4.5f, float.NaN, 1.0f), new float3(3.4f, 2.7f, 1.0f), new float3(3.4f, 0.7f, 1.0f), new float3(-3.4f, 1.2f, 1.1f) }; TestUtils.ThrowsException <System.ArgumentException>( () => PolygonCollider.CreateTriangle(vertices[0], vertices[1], vertices[2]) ); TestUtils.ThrowsException <System.ArgumentException>( () => PolygonCollider.CreateQuad(vertices[0], vertices[1], vertices[2], vertices[3]) ); } // non-planar quad { float3[] nonPlanarQuad = { new float3(-4.5f, 0.0f, 1.0f), new float3(3.4f, 0.7f, 1.0f), new float3(3.4f, 2.7f, 1.0f), new float3(-3.4f, 1.2f, 1.1f) }; TestUtils.ThrowsException <System.ArgumentException>( () => PolygonCollider.CreateQuad(nonPlanarQuad[0], nonPlanarQuad[1], nonPlanarQuad[2], nonPlanarQuad[3]) ); } // non-planar quad unsorted { float3[] nonPlanarQuad = { new float3(-4.5f, -0.30f, 1.0f), new float3(3.4f, 2.7f, 1.0f), new float3(3.4f, -0.7f, 1.0f), new float3(-3.4f, 1.2f, 1.1f) }; TestUtils.ThrowsException <System.ArgumentException>( () => PolygonCollider.CreateQuad(nonPlanarQuad[0], nonPlanarQuad[1], nonPlanarQuad[2], nonPlanarQuad[3]) ); } }
public void TestBoxColliderCreateInvalid() { var geometry = new BoxGeometry { Center = new float3(1.0f, 0.0f, 0.0f), Orientation = quaternion.AxisAngle(math.normalize(new float3(4.3f, 1.2f, 0.1f)), 1085.0f), Size = new float3(1.0f, 2.0f, 3.0f), BevelRadius = 0.45f }; // Invalid center, positive infinity { var invalidGeometry = geometry; invalidGeometry.Center = new float3(float.PositiveInfinity, 1.0f, 1.0f); TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Invalid center, positive infinity { var invalidGeometry = geometry; invalidGeometry.Center = new float3(float.NegativeInfinity, 1.0f, 1.0f); TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Invalid center, nan { var invalidGeometry = geometry; invalidGeometry.Center = new float3(float.NaN, 1.0f, 1.0f); TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Negative size { var invalidGeometry = geometry; invalidGeometry.Size = new float3(-1.0f, 1.0f, 1.0f); TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Invalid size, positive inf { var invalidGeometry = geometry; invalidGeometry.Size = new float3(float.PositiveInfinity, 1.0f, 1.0f); TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Invalid size, negative inf { var invalidGeometry = geometry; invalidGeometry.Size = new float3(float.NegativeInfinity, 1.0f, 1.0f); TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Invalid size, nan { var invalidGeometry = geometry; invalidGeometry.Size = new float3(float.NaN, 1.0f, 1.0f); TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Negative bevel radius { var invalidGeometry = geometry; invalidGeometry.BevelRadius = -0.0001f; TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Invalid bevel radius, +inf { var invalidGeometry = geometry; invalidGeometry.BevelRadius = float.PositiveInfinity; TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Invalid bevel radius, -inf { var invalidGeometry = geometry; invalidGeometry.BevelRadius = float.NegativeInfinity; TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } // Invalid bevel radius, nan { var invalidGeometry = geometry; invalidGeometry.BevelRadius = float.NaN; TestUtils.ThrowsException <ArgumentException>(() => BoxCollider.Create(invalidGeometry)); } }
public void TestCapsuleColliderCreateInvalid() { float3 v0 = new float3(5.66f, -6.72f, 0.12f); float3 v1 = new float3(0.98f, 8.88f, 9.54f); float radius = 0.65f; // v0, +inf { float3 invalidV0 = new float3(float.PositiveInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidV0, v1, radius)); } // v0, -inf { float3 invalidV0 = new float3(float.NegativeInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidV0, v1, radius)); } // v0, nan { float3 invalidV0 = new float3(float.NaN, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidV0, v1, radius)); } // v1, +inf { float3 invalidV1 = new float3(float.PositiveInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(v0, invalidV1, radius)); } // v1, -inf { float3 invalidV1 = new float3(float.NegativeInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(v0, invalidV1, radius)); } // v1, nan { float3 invalidV1 = new float3(float.NaN, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(v0, invalidV1, radius)); } // negative radius { float invalidRadius = -0.54f; TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(v0, v1, invalidRadius)); } // radius, +inf { float invalidRadius = float.PositiveInfinity; TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(v0, v1, invalidRadius)); } // radius, -inf { float invalidRadius = float.NegativeInfinity; TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(v0, v1, invalidRadius)); } // radius, nan { float invalidRadius = float.NaN; TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(v0, v1, invalidRadius)); } }
public void TestCapsuleColliderCreateInvalid() { var geometry = new CapsuleGeometry { Vertex0 = new float3(5.66f, -6.72f, 0.12f), Vertex1 = new float3(0.98f, 8.88f, 9.54f), Radius = 0.65f }; // v0, +inf { var invalidGeometry = geometry; invalidGeometry.Vertex0 = new float3(float.PositiveInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // v0, -inf { var invalidGeometry = geometry; invalidGeometry.Vertex0 = new float3(float.NegativeInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // v0, nan { var invalidGeometry = geometry; invalidGeometry.Vertex0 = new float3(float.NaN, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // v1, +inf { var invalidGeometry = geometry; invalidGeometry.Vertex1 = new float3(float.PositiveInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // v1, -inf { var invalidGeometry = geometry; invalidGeometry.Vertex1 = new float3(float.NegativeInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // v1, nan { var invalidGeometry = geometry; invalidGeometry.Vertex1 = new float3(float.NaN, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // negative radius { var invalidGeometry = geometry; invalidGeometry.Radius = -0.54f; TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // radius, +inf { var invalidGeometry = geometry; invalidGeometry.Radius = float.PositiveInfinity; TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // radius, -inf { var invalidGeometry = geometry; invalidGeometry.Radius = float.NegativeInfinity; TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } // radius, nan { var invalidGeometry = geometry; invalidGeometry.Radius = float.NaN; TestUtils.ThrowsException <System.ArgumentException>(() => CapsuleCollider.Create(invalidGeometry)); } }
public void TestSphereColliderCreateInvalid() { float3 center = new float3(-10.34f, 0.0f, -1.54f); float radius = 1.25f; // positive inf center { float3 invalidCenter = new float3(float.PositiveInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>( () => SphereCollider.Create(invalidCenter, radius) ); } // negative inf center { float3 invalidCenter = new float3(float.NegativeInfinity, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>( () => SphereCollider.Create(invalidCenter, radius) ); } // nan center { float3 invalidCenter = new float3(float.NaN, 0.0f, 0.0f); TestUtils.ThrowsException <System.ArgumentException>( () => SphereCollider.Create(invalidCenter, radius) ); } // negative radius { float invalidRadius = -0.5f; TestUtils.ThrowsException <System.ArgumentException>( () => SphereCollider.Create(center, invalidRadius) ); } // positive inf radius { float invalidRadius = float.PositiveInfinity; TestUtils.ThrowsException <System.ArgumentException>( () => SphereCollider.Create(center, invalidRadius) ); } // negative inf radius { float invalidRadius = float.NegativeInfinity; TestUtils.ThrowsException <System.ArgumentException>( () => SphereCollider.Create(center, invalidRadius) ); } // nan radius { float invalidRadius = float.NaN; TestUtils.ThrowsException <System.ArgumentException>( () => SphereCollider.Create(center, invalidRadius) ); } }