public void AddEdgeTest()
        {
            var dcel = new DCEL();
            var v1   = dcel.AddVertex(new DCELVertex(0, 0));
            var v2   = dcel.AddVertex(new Vector2(2, 2));

            dcel.AddEdge(v1, v2);
            Assert.AreEqual(1, dcel.EdgeCount);
            dcel.AddEdge(new Vector2(0, 2), new Vector2(2, 0));
            Assert.AreEqual(4, dcel.EdgeCount);

            Assert.Throws <GeomException>(() => dcel.AddEdge(new DCELVertex(-1, -1), v1));
        }
        public void AdjacentEdgesTest()
        {
            var dcel = new DCEL();
            var v1   = dcel.AddVertex(new DCELVertex(0, 0));
            var v2   = dcel.AddVertex(new DCELVertex(10, 10));
            var v3   = dcel.AddVertex(new DCELVertex(20, 0));

            dcel.AddEdge(v1, v2);
            dcel.AddEdge(v2, v3);

            Assert.AreEqual(2, dcel.AdjacentEdges(v1).Count);
            Assert.AreEqual(4, dcel.AdjacentEdges(v2).Count);
            Assert.AreEqual(2, dcel.AdjacentEdges(v3).Count);
            Assert.AreEqual(1, dcel.OutgoingEdges(v1).Count);
            Assert.AreEqual(2, dcel.OutgoingEdges(v2).Count);
            Assert.AreEqual(1, dcel.OutgoingEdges(v3).Count);
        }
예제 #3
0
        static void Main(string[] args)
        {
            DCEL <Vector2> dcel = new DCEL <Vector2>("test", "this is a test");

            List <VectorBase> vectors = new List <VectorBase>();

            vectors.Add(new Vector2(3.0d, 4.5d));
            dcel.AddVertex(vectors[0] as Vector2);
        }
        public void FindVertexTest()
        {
            var        dcel = new DCEL();
            var        v1   = dcel.AddVertex(new DCELVertex(1, -1));
            DCELVertex v2;

            Assert.IsTrue(dcel.FindVertex(new Vector2(1, -1), out v2));
            Assert.AreEqual(v1, v2);
            Assert.IsFalse(dcel.FindVertex(new Vector2(0, 0), out v2));
            Assert.IsNull(v2);
        }
        public void InnerFacesTest()
        {
            var dcel = new DCEL();

            // create large triangle
            var v1 = dcel.AddVertex(new DCELVertex(0, 0));
            var v2 = dcel.AddVertex(new DCELVertex(10, 10));
            var v3 = dcel.AddVertex(new DCELVertex(20, 0));

            dcel.AddEdge(v1, v2);
            dcel.AddEdge(v2, v3);
            dcel.AddEdge(v3, v1);


            // create smaller inner triangle
            var v4 = dcel.AddVertex(new DCELVertex(9, 2));
            var v5 = dcel.AddVertex(new DCELVertex(10, 3));
            var v6 = dcel.AddVertex(new DCELVertex(11, 2));

            dcel.AddEdge(v4, v5);
            dcel.AddEdge(v5, v6);
            dcel.AddEdge(v6, v4);

            Assert.AreEqual(6, dcel.VertexCount);
            Assert.AreEqual(6, dcel.EdgeCount);
            Assert.AreEqual(3, dcel.FaceCount);
            Assert.AreEqual(1, dcel.OuterFace.InnerComponents.Count);
            Assert.AreEqual(1, dcel.InnerFaces.FirstOrDefault().InnerComponents.Count);

            // create outside triangle
            // create smaller inner triangle
            var v7 = dcel.AddVertex(new DCELVertex(-1, -1));
            var v8 = dcel.AddVertex(new DCELVertex(-2, -2));
            var v9 = dcel.AddVertex(new DCELVertex(-3, -1));

            dcel.AddEdge(v7, v8);
            dcel.AddEdge(v8, v9);
            dcel.AddEdge(v9, v7);

            Assert.AreEqual(9, dcel.VertexCount);
            Assert.AreEqual(9, dcel.EdgeCount);
            Assert.AreEqual(4, dcel.FaceCount);
            Assert.AreEqual(2, dcel.OuterFace.InnerComponents.Count);
        }