public void testClone() { IndexData indexData; IndexData clone; // with basic quad data indexData = new IndexData(); indexData.AddTriangle(1, 2, 3); indexData.AddTriangle(4, 5, 6); clone = indexData.Clone(); Assert.AreEqual(2, clone.NumTriangles); Assert.AreEqual(1, clone.GetIndex(0)); Assert.AreEqual(3, clone.GetIndex(2)); Assert.AreEqual(5, clone.GetIndex(4)); // with arbitrary data indexData = new IndexData(); indexData.AddTriangle(0, 1, 2); indexData.AddTriangle(1, 3, 2); clone = indexData.Clone(); Assert.AreEqual(2, clone.NumTriangles); Assert.AreEqual(1, clone.GetIndex(1)); Assert.AreEqual(2, clone.GetIndex(2)); Assert.AreEqual(3, clone.GetIndex(4)); }
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)); }
public void testToVector() { var source = new IndexData(); source.AddTriangle(1, 2, 3); source.AddTriangle(4, 5, 6); short[] expected = new short[6] { 1, 2, 3, 4, 5, 6 }; short[] actual = new short[1]; source.ToVector(ref actual); Assert.AreEqual(expected, actual); }
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)); }
public void TestColor() { VertexData vertexData = new VertexData(); vertexData.NumVertices = 3; IndexData indexData = new IndexData(); indexData.AddTriangle(0, 1, 2); Mesh mesh = new Mesh(vertexData, indexData); mesh.SetVertexColor(0, 0xff0000); mesh.SetVertexColor(1, 0x00ff00); mesh.SetVertexColor(2, 0x0000ff); Assert.AreEqual(0xff0000, mesh.GetVertexColor(0)); Assert.AreEqual(0x00ff00, mesh.GetVertexColor(1)); Assert.AreEqual(0x0000ff, mesh.GetVertexColor(2)); mesh.Color = 0xf0f0f0; for (int i = 0; i < 3; ++i) { Assert.AreEqual(0xf0f0f0, mesh.GetVertexColor(i)); } }
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)); }
public void testClear() { IndexData indexData = new IndexData(); indexData.AddTriangle(1, 2, 4); indexData.Clear(); Assert.AreEqual(0, indexData.NumIndices); Assert.IsTrue(indexData.UseQuadLayout); }
public void TestHitTest() { // + 0 // /| // / | // 1--2--3 // | / // |/ // 4 VertexData vertexData = new VertexData(); vertexData.SetPoint(0, 1, 0); vertexData.SetPoint(1, 0, 1); vertexData.SetPoint(2, 1, 1); vertexData.SetPoint(3, 2, 1); vertexData.SetPoint(4, 1, 2); IndexData indexData = new IndexData(); indexData.AddTriangle(0, 2, 1); indexData.AddTriangle(2, 3, 4); Mesh mesh = new Mesh(vertexData, indexData); Assert.IsNull(mesh.HitTest(Point.Create(0.49f, 0.49f))); Assert.IsNull(mesh.HitTest(Point.Create(1.01f, 0.99f))); Assert.IsNull(mesh.HitTest(Point.Create(0.99f, 1.01f))); Assert.IsNull(mesh.HitTest(Point.Create(1.51f, 1.51f))); Assert.AreEqual(mesh, mesh.HitTest(Point.Create(0.51f, 0.51f))); Assert.AreEqual(mesh, mesh.HitTest(Point.Create(0.99f, 0.99f))); Assert.AreEqual(mesh, mesh.HitTest(Point.Create(1.01f, 1.01f))); Assert.AreEqual(mesh, mesh.HitTest(Point.Create(1.49f, 1.49f))); mesh.Visible = false; Assert.IsNull(mesh.HitTest(Point.Create(0.75f, 0.75f))); mesh.Visible = true; mesh.Touchable = false; Assert.IsNull(mesh.HitTest(Point.Create(0.75f, 0.75f))); }
public void TestVertexPosition() { VertexData vertexData = new VertexData(); vertexData.NumVertices = 3; IndexData indexData = new IndexData(); indexData.AddTriangle(0, 1, 2); Mesh mesh = new Mesh(vertexData, indexData); mesh.SetVertexPosition(1, 1, 0); mesh.SetVertexPosition(2, 1, 1); ComparePoints(mesh.GetVertexPosition(0), Point.Create()); ComparePoints(mesh.GetVertexPosition(1), Point.Create(1, 0)); ComparePoints(mesh.GetVertexPosition(2), Point.Create(1, 1)); }
public void TestAlpha() { VertexData vertexData = new VertexData(); vertexData.NumVertices = 3; IndexData indexData = new IndexData(); indexData.AddTriangle(0, 1, 2); Mesh mesh = new Mesh(vertexData, indexData); mesh.SetVertexAlpha(0, 0.2f); mesh.SetVertexAlpha(1, 0.5f); mesh.SetVertexAlpha(2, 0.8f); float E = 0.02f; AssertAreEqualWithSmallError(mesh.GetVertexAlpha(0), 0.2f, "", E); AssertAreEqualWithSmallError(mesh.GetVertexAlpha(1), 0.5f, "", E); AssertAreEqualWithSmallError(mesh.GetVertexAlpha(2), 0.8f, "", E); }
public void TestGetBounds() { VertexData vertexData = new VertexData(); vertexData.SetPoint(0, 10, 10); vertexData.SetPoint(1, 20, 10); vertexData.SetPoint(2, 10, 20); IndexData indexData = new IndexData(); indexData.AddTriangle(0, 1, 2); Mesh mesh = new Mesh(vertexData, indexData); Rectangle expected = Rectangle.Create(10, 10, 10, 10); CompareRectangles(expected, mesh.Bounds); CompareRectangles(expected, mesh.GetBounds(mesh)); mesh.Rotation = (float)Math.PI / 2.0f; expected.SetTo(-20, 10, 10, 10); CompareRectangles(expected, mesh.Bounds); }
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)); }