public void CoplanarAndSeparated()
        {
            var tA = new Triangle(new Vector3(10, 0, -10), new Vector3(-10, 0, -10), new Vector3(0, 0, 10));
            var tB = new Triangle(new Vector3(10, 0, 20), new Vector3(-10, 0, 20), new Vector3(0, 0, 40));

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        Vector3 p, n;
                        float   d;
                        bool    haveContact = TriangleTriangleAlgorithm.GetContact(ref tA, ref tB, out p, out n, out d);

                        Assert.AreEqual(false, haveContact);

                        // "Rotate" triangle to test next edges.
                        var oldB = tB;
                        tB[0] = oldB[1];
                        tB[1] = oldB[2];
                        tB[2] = oldB[0];
                    }

                    // "Rotate" triangle to test next edges.
                    var oldA = tA;
                    tA[0] = oldA[1];
                    tA[1] = oldA[2];
                    tA[2] = oldA[0];
                }

                MathHelper.Swap(ref tA, ref tB);
            }
        }
        public void BothFacesDegenerate()
        {
            var tA = new Triangle(new Vector3(-10, 0, 0), new Vector3(-10, 0, 0), new Vector3(10, 0, 0));
            var tB = new Triangle(new Vector3(0, 0, -10), new Vector3(0, 0, 10), new Vector3(0, 0, 10));

            Vector3 p, n;
            float   d;
            bool    haveContact = TriangleTriangleAlgorithm.GetContact(ref tA, ref tB, out p, out n, out d);

            Assert.AreEqual(false, haveContact);
        }
        public void SeparationEdgeA2EdgeB2_1()
        {
            var tA = new Triangle(new Vector3(0, 0, -10), new Vector3(-10, 0, 0), new Vector3(0, 0, 10));
            var tB = new Triangle(new Vector3(1, 10, 0), new Vector3(10, 0, 0), new Vector3(1, -10, 0));

            Vector3 p, n;
            float   d;
            bool    haveContact = TriangleTriangleAlgorithm.GetContact(ref tA, ref tB, out p, out n, out d);

            Assert.AreEqual(false, haveContact);
        }
        public void PointPoint()
        {
            var a  = new Vector3(1, 1, 1);
            var tA = new Triangle(a, a, a);
            var tB = new Triangle(a, a, a);

            Vector3 p, n;
            float   d;
            bool    haveContact = TriangleTriangleAlgorithm.GetContact(ref tA, ref tB, out p, out n, out d);

            Assert.AreEqual(false, haveContact);
        }
        public void CoplanarAndEdge()
        {
            var tA = new Triangle(new Vector3(10, 0, -10), new Vector3(-10, 0, -10), new Vector3(0, 0, 0));
            var tB = new Triangle(new Vector3(10, 0, -1), new Vector3(-10, 0, -1), new Vector3(10, 0, -2));

            for (int a = 0; a < 2; a++)
            {
                for (int b = 0; b < 2; b++)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            for (int k = 0; k < 3; k++)
                            {
                                Vector3 p, n;
                                float   d;
                                bool    haveContact = TriangleTriangleAlgorithm.GetContact(ref tA, ref tB, out p, out n, out d);

                                Assert.AreEqual(true, haveContact);
                                Assert.IsTrue(Vector3.AreNumericallyEqual(new Vector3(0, 1, 0), n) ||
                                              Vector3.AreNumericallyEqual(new Vector3(0, -1, 0), n));
                                Assert.IsTrue(GeometryHelper.IsOver(tA, p, 0.00001f));
                                Assert.IsTrue(GeometryHelper.IsOver(tB, p, 0.00001f));
                                //Assert.IsTrue(Vector3.AreNumericallyEqual(?, p));
                                Assert.AreEqual(0, d);

                                // "Rotate" triangle to test next edges.
                                var oldB = tB;
                                tB[0] = oldB[1];
                                tB[1] = oldB[2];
                                tB[2] = oldB[0];
                            }

                            // "Rotate" triangle to test next edges.
                            var oldA = tA;
                            tA[0] = oldA[1];
                            tA[1] = oldA[2];
                            tA[2] = oldA[0];
                        }

                        MathHelper.Swap(ref tA, ref tB);
                    }

                    // Change winding order.
                    MathHelper.Swap(ref tB.Vertex0, ref tB.Vertex1);
                }

                // Change winding order.
                MathHelper.Swap(ref tA.Vertex0, ref tA.Vertex1);
            }
        }
        public void VertexA0VertexB0()
        {
            var tA = new Triangle(new Vector3(10, 0, -10), new Vector3(-10, 0, -10), new Vector3(0, 0, 10));
            var tB = new Triangle(new Vector3(10, 0, -10), new Vector3(10, 10, 0), new Vector3(-10, 10, 0));

            Vector3 p, n;
            float   d;
            bool    haveContact = TriangleTriangleAlgorithm.GetContact(ref tA, ref tB, out p, out n, out d);

            Assert.AreEqual(true, haveContact);
            Assert.IsTrue(Vector3.AreNumericallyEqual(tA.Vertex0, p));
            Assert.IsTrue(Numeric.AreEqual(0, d));
        }
        public void FaceBDegenerate()
        {
            var tB = new Triangle(new Vector3(-1, 0, 0), new Vector3(10, 0, -0), new Vector3(10, 0, 0));
            var tA = new Triangle(new Vector3(0, -10, -10), new Vector3(0, -10, 10), new Vector3(0, 10, 0));

            Vector3 p, n;
            float   d;
            bool    haveContact = TriangleTriangleAlgorithm.GetContact(ref tA, ref tB, out p, out n, out d);

            Assert.AreEqual(true, haveContact);
            Assert.IsTrue(Vector3.AreNumericallyEqual(new Vector3(-0.5f, 0, 0), p));
            Assert.IsTrue(Vector3.AreNumericallyEqual(new Vector3(1, 0, 0), n));
            Assert.IsTrue(Numeric.AreEqual(1, d));
        }
        public void FaceEdge()
        {
            var tA = new Triangle(new Vector3(10, 0, -10), new Vector3(-10, 0, -10), new Vector3(0, 0, 10));
            var tB = new Triangle(new Vector3(-10, -1, 0), new Vector3(10, -1, 0), new Vector3(0, 10, 0));

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        Vector3 p, n;
                        float   d;
                        bool    haveContact = TriangleTriangleAlgorithm.GetContact(ref tA, ref tB, out p, out n, out d);

                        Assert.AreEqual(true, haveContact);
                        Assert.IsTrue(Vector3.AreNumericallyEqual(new Vector3(-5, -0.5f, 0), p) ||
                                      Vector3.AreNumericallyEqual(new Vector3(5, -0.5f, 0), p));
                        Assert.IsTrue(GeometryHelper.IsOver(tB, p));
                        if (i == 0)
                        {
                            Assert.IsTrue(Vector3.AreNumericallyEqual(new Vector3(0, 1, 0), n));
                        }
                        else
                        {
                            Assert.IsTrue(Vector3.AreNumericallyEqual(new Vector3(0, -1, 0), n));
                        }
                        Assert.IsTrue(Numeric.AreEqual(1, d));

                        // "Rotate" triangle to test next edges.
                        var oldB = tB;
                        tB[0] = oldB[1];
                        tB[1] = oldB[2];
                        tB[2] = oldB[0];
                    }

                    // "Rotate" triangle to test next edges.
                    var oldA = tA;
                    tA[0] = oldA[1];
                    tA[1] = oldA[2];
                    tA[2] = oldA[0];
                }

                MathHelper.Swap(ref tA, ref tB);
            }
        }