Exemplo n.º 1
0
        public void testAppendTriangle()
        {
            IndexData indexData = new IndexData();

            // basic quad data

            indexData.AddTriangle(0, 1, 2);
            indexData.AddTriangle(1, 3, 2);

            Assert.IsTrue(indexData.UseQuadLayout);
            Assert.AreEqual(1, indexData.NumQuads);
            Assert.AreEqual(2, indexData.NumTriangles);
            Assert.AreEqual(6, indexData.NumIndices);

            Assert.AreEqual(0, indexData.GetIndex(0));
            Assert.AreEqual(1, indexData.GetIndex(1));
            Assert.AreEqual(2, indexData.GetIndex(2));
            Assert.AreEqual(1, indexData.GetIndex(3));
            Assert.AreEqual(3, indexData.GetIndex(4));
            Assert.AreEqual(2, indexData.GetIndex(5));

            indexData.NumTriangles = 0;
            Assert.AreEqual(0, indexData.NumIndices);
            Assert.AreEqual(0, indexData.NumTriangles);

            // arbitrary data
            indexData.AddTriangle(1, 3, 2);
            Assert.IsFalse(indexData.UseQuadLayout);
            Assert.AreEqual(1, indexData.NumTriangles);
            Assert.AreEqual(3, indexData.NumIndices);

            Assert.AreEqual(1, indexData.GetIndex(0));
            Assert.AreEqual(3, indexData.GetIndex(1));
            Assert.AreEqual(2, indexData.GetIndex(2));
        }
Exemplo n.º 2
0
        public void testSetNumIndices()
        {
            var indexData = new IndexData();

            indexData.NumIndices = 6;

            Assert.AreEqual(0, indexData.GetIndex(0));
            Assert.AreEqual(1, indexData.GetIndex(1));
            Assert.AreEqual(2, indexData.GetIndex(2));
            Assert.AreEqual(1, indexData.GetIndex(3));
            Assert.AreEqual(3, indexData.GetIndex(4));
            Assert.AreEqual(2, indexData.GetIndex(5));

            indexData.NumIndices = 0;
            Assert.AreEqual(0, indexData.NumIndices);

            indexData.SetIndex(0, 1);
            Assert.IsFalse(indexData.UseQuadLayout);

            indexData.NumIndices = 3;
            Assert.AreEqual(1, indexData.GetIndex(0));
            Assert.AreEqual(0, indexData.GetIndex(1));
            Assert.AreEqual(0, indexData.GetIndex(2));

            indexData.NumIndices = 0;
            Assert.AreEqual(0, indexData.NumIndices);
            Assert.IsTrue(indexData.UseQuadLayout);
        }
Exemplo n.º 3
0
        public void testOffsetIndices()
        {
            var indexData = new IndexData();

            indexData.AddTriangle(1, 2, 3);
            indexData.AddTriangle(4, 5, 6);

            indexData.OffsetIndices(10, 1, 3);
            Assert.AreEqual(1, indexData.GetIndex(0));
            Assert.AreEqual(12, indexData.GetIndex(1));
            Assert.AreEqual(13, indexData.GetIndex(2));
            Assert.AreEqual(14, indexData.GetIndex(3));
            Assert.AreEqual(5, indexData.GetIndex(4));
        }
Exemplo n.º 4
0
        public void testCopyToEdgeCases()
        {
            var source = new IndexData();

            source.NumIndices = 6;

            var target = new IndexData();

            target.NumIndices = 6;

            source.CopyTo(target, 1, 1, 0, 1);
            Assert.IsTrue(target.UseQuadLayout);

            source.CopyTo(target, 3, 0, 1, 1);
            Assert.IsTrue(target.UseQuadLayout);

            source.CopyTo(target, 1, 1, 0, 2);
            Assert.IsTrue(target.UseQuadLayout);

            source.CopyTo(target, 10, 5, 2, 2);
            Assert.IsTrue(target.UseQuadLayout);

            source.CopyTo(target, 13, 8, 1, 4);
            Assert.IsTrue(target.UseQuadLayout);

            source.CopyTo(target, 10, 3, 4, 1);
            Assert.IsFalse(target.UseQuadLayout);
            Assert.AreEqual(6, target.GetIndex(10));
        }
Exemplo n.º 5
0
        public void testCopyToWithOffset()
        {
            var source = new IndexData();

            source.AddTriangle(1, 2, 3);
            source.AddTriangle(4, 5, 6);

            var target = new IndexData();

            target.AddTriangle(7, 8, 9);
            source.CopyTo(target, 1, 10, 3, 3);

            Assert.AreEqual(4, target.NumIndices);
            Assert.AreEqual(7, target.GetIndex(0));
            Assert.AreEqual(14, target.GetIndex(1));
            Assert.AreEqual(15, target.GetIndex(2));
            Assert.AreEqual(16, target.GetIndex(3));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Determines if a point is inside a mesh that is spawned up by the given
        /// vertex- and index-data.
        /// </summary>
        public static bool ContainsPoint(VertexData vertexData, IndexData indexData, Point point)
        {
            int  i;
            bool result     = false;
            int  numIndices = indexData.NumIndices;

            for (i = 0; i < numIndices; i += 3)
            {
                var p0 = vertexData.GetPoint(indexData.GetIndex(i));
                var p1 = vertexData.GetPoint(indexData.GetIndex(i + 1));
                var p2 = vertexData.GetPoint(indexData.GetIndex(i + 2));

                if (MathUtil.IsPointInTriangle(point, p0, p1, p2))
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public void testSetIsBasicQuadData()
        {
            var indexData = new IndexData();

            indexData.NumIndices = 6;
            Assert.IsTrue(indexData.UseQuadLayout);
            Assert.AreEqual(1, indexData.GetIndex(3));

            indexData.SetIndex(3, 10);
            Assert.IsFalse(indexData.UseQuadLayout);

            indexData.UseQuadLayout = true;
            Assert.AreEqual(1, indexData.GetIndex(3));

            // basic quad data must be sized correctly
            indexData.UseQuadLayout = false;
            indexData.NumIndices    = 12;
            indexData.UseQuadLayout = true;
            indexData.UseQuadLayout = false;
            Assert.AreEqual(6, indexData.GetIndex(11));
        }
Exemplo n.º 8
0
        public void testSetIndex()
        {
            IndexData indexData = new IndexData();

            // basic quad data
            indexData.SetIndex(0, 0);
            indexData.SetIndex(1, 1);
            indexData.SetIndex(2, 2);

            Assert.IsTrue(indexData.UseQuadLayout);
            Assert.AreEqual(0, indexData.GetIndex(0));
            Assert.AreEqual(1, indexData.GetIndex(1));
            Assert.AreEqual(2, indexData.GetIndex(2));
            Assert.AreEqual(3, indexData.NumIndices);

            // setting outside the bounds while keeping quad index rules -> fill up with quad data
            indexData.SetIndex(5, 2);
            Assert.IsTrue(indexData.UseQuadLayout);
            Assert.AreEqual(2, indexData.NumTriangles);
            Assert.AreEqual(1, indexData.GetIndex(3));
            Assert.AreEqual(3, indexData.GetIndex(4));
            Assert.AreEqual(2, indexData.GetIndex(5));

            // arbitrary data
            indexData.SetIndex(6, 5);
            Assert.IsFalse(indexData.UseQuadLayout);
            Assert.AreEqual(7, indexData.NumIndices);
            Assert.AreEqual(5, indexData.GetIndex(6));

            // settings outside the bounds -> fill up with zeroes
            indexData.SetIndex(9, 1);
            Assert.AreEqual(10, indexData.NumIndices);
            Assert.AreEqual(0, indexData.GetIndex(7));
            Assert.AreEqual(0, indexData.GetIndex(8));
            Assert.AreEqual(1, indexData.GetIndex(9));
        }
Exemplo n.º 9
0
        public void testCopyTo()
        {
            // arbitrary data -> arbitrary data
            var source = new IndexData();

            source.AddTriangle(1, 2, 3);
            source.AddTriangle(4, 5, 6);

            var target = new IndexData();

            target.AddTriangle(7, 8, 9);
            source.CopyTo(target, 0, 0, 3, 3);

            Assert.AreEqual(3, target.NumIndices);
            Assert.AreEqual(4, target.GetIndex(0));
            Assert.AreEqual(5, target.GetIndex(1));
            Assert.AreEqual(6, target.GetIndex(2));

            source.CopyTo(target, 3);
            Assert.AreEqual(9, target.NumIndices);

            // quad data -> quad data
            source.Clear();
            target.Clear();

            source.AddTriangle(0, 1, 2);
            target.AddQuad(0, 1, 2, 3);
            source.CopyTo(target, 6, 4);

            Assert.IsTrue(target.UseQuadLayout);
            Assert.AreEqual(9, target.NumIndices);
            Assert.AreEqual(2, target.GetIndex(5));
            Assert.AreEqual(4, target.GetIndex(6));
            Assert.AreEqual(5, target.GetIndex(7));
            Assert.AreEqual(6, target.GetIndex(8));

            // quad data -> arbitrary data
            target.Clear();
            target.AddQuad(1, 2, 3, 4);
            source.CopyTo(target, 6, 4);

            Assert.IsTrue(source.UseQuadLayout);
            Assert.IsFalse(target.UseQuadLayout);
            Assert.AreEqual(9, target.NumIndices);
            Assert.AreEqual(3, target.GetIndex(5));
            Assert.AreEqual(4, target.GetIndex(6));
            Assert.AreEqual(5, target.GetIndex(7));
            Assert.AreEqual(6, target.GetIndex(8));

            // arbitrary data -> quad data
            source.Clear();
            source.AddTriangle(1, 2, 3);
            target.Clear();
            target.AddQuad(0, 1, 2, 3);
            source.CopyTo(target, 6, 4);

            Assert.IsFalse(source.UseQuadLayout);
            Assert.IsFalse(target.UseQuadLayout);
            Assert.AreEqual(9, target.NumIndices);
            Assert.AreEqual(2, target.GetIndex(5));
            Assert.AreEqual(5, target.GetIndex(6));
            Assert.AreEqual(6, target.GetIndex(7));
            Assert.AreEqual(7, target.GetIndex(8));
        }
Exemplo n.º 10
0
        public void testAppendQuad()
        {
            var indexData = new IndexData();

            // basic quad data

            indexData.AddQuad(0, 1, 2, 3);
            indexData.AddQuad(4, 5, 6, 7);

            Assert.IsTrue(indexData.UseQuadLayout);
            Assert.AreEqual(2, indexData.NumQuads);
            Assert.AreEqual(4, indexData.NumTriangles);
            Assert.AreEqual(12, indexData.NumIndices);

            Assert.AreEqual(0, indexData.GetIndex(0));
            Assert.AreEqual(1, indexData.GetIndex(1));
            Assert.AreEqual(2, indexData.GetIndex(2));
            Assert.AreEqual(1, indexData.GetIndex(3));
            Assert.AreEqual(3, indexData.GetIndex(4));
            Assert.AreEqual(2, indexData.GetIndex(5));
            Assert.AreEqual(4, indexData.GetIndex(6));
            Assert.AreEqual(5, indexData.GetIndex(7));
            Assert.AreEqual(6, indexData.GetIndex(8));
            Assert.AreEqual(5, indexData.GetIndex(9));
            Assert.AreEqual(7, indexData.GetIndex(10));
            Assert.AreEqual(6, indexData.GetIndex(11));

            indexData.NumTriangles = 0;
            Assert.AreEqual(0, indexData.NumIndices);
            Assert.AreEqual(0, indexData.NumQuads);

            // arbitrary data
            indexData.AddQuad(0, 1, 3, 2);
            Assert.IsFalse(indexData.UseQuadLayout);
            Assert.AreEqual(1, indexData.NumQuads);
            Assert.AreEqual(2, indexData.NumTriangles);
            Assert.AreEqual(6, indexData.NumIndices);

            Assert.AreEqual(0, indexData.GetIndex(0));
            Assert.AreEqual(1, indexData.GetIndex(1));
            Assert.AreEqual(3, indexData.GetIndex(2));
            Assert.AreEqual(1, indexData.GetIndex(3));
            Assert.AreEqual(2, indexData.GetIndex(4));
            Assert.AreEqual(3, indexData.GetIndex(5));
        }