Пример #1
0
        public void TestInvalidObjectComparison()
        {
            Vertex v1 = new Vertex(0.1234, 0.1234);
            LAV lav = new LAV();

            Assert.IsFalse(v1.Equals(lav));
        }
Пример #2
0
        public void ReadInput(out LAV listOfActiveVertices)
        {
            listOfActiveVertices = new LAV();

            while (inputReader.IsNotEmpty())
            {
                listOfActiveVertices.Add(inputReader.GetCurrentVertex());
            }
        }
Пример #3
0
        public void TestBreakAndCreateNew()
        {
            SLAV slav = new SLAV();

            //NEED TO MAINTAIN THIS LIST FOR TESTING PURPOSES
            LAV localLav = new LAV();

            Vertex v1 = new Vertex(0, 3);
            Vertex v2 = new Vertex(2, 0);
            Vertex v3 = new Vertex(4, 2);
            Vertex v4 = new Vertex(6, 0);
            Vertex v5 = new Vertex(8, 3);

            localLav.Add(v1);
            localLav.Add(v2);
            localLav.Add(v3);
            localLav.Add(v4);
            localLav.Add(v5);

            SSLOperations.SetVertexType(localLav);
            SSLOperations.ComputeAngleBisectors(localLav);

            slav.Insert(v1, 0);
            slav.Insert(v2, 0);
            slav.Insert(v3, 0);
            slav.Insert(v4, 0);
            slav.Insert(v5, 0);

            SSLOperations.SetVertexType(slav.Get(0));
            SSLOperations.ComputeAngleBisectors(slav.Get(0));

            LAV lav = slav.Get(0);
            Assert.AreEqual(v1, lav.Get(1));
            Assert.AreEqual(v2, lav.Get(2));
            Assert.AreEqual(v3, lav.Get(3));
            Assert.AreEqual(Vertex.VertexType.Split, lav.Get(3).Type);
            Assert.AreEqual(v4, lav.Get(4));
            Assert.AreEqual(v5, lav.Get(5));

            slav.BreakAndCreateNew(v3, 0);

            lav = slav.Get(0);

            Assert.AreEqual(v1, lav.Get(1));
            Assert.AreEqual(v2, lav.Get(2));
            Assert.AreEqual(new Vertex(4, 3), lav.Get(3));
            Assert.AreEqual(v1, lav.Get(3).GetNextVertex());

            lav = slav.Get(1);

            Assert.AreEqual(new Vertex(4, 3), lav.Get(1));
            Assert.AreEqual(v4, lav.Get(2));
            Assert.AreEqual(v5, lav.Get(3));

            Assert.AreEqual(new Vertex(4, 3), lav.Get(3).GetNextVertex());
        }
Пример #4
0
        public void TestAngleBisectorsNonConvexPolygon()
        {
            LAV listOfActiveVertices2 = new LAV();
            listOfActiveVertices2.Add(new Vertex(0, 6));
            listOfActiveVertices2.Add(new Vertex(0, 0));
            listOfActiveVertices2.Add(new Vertex(4, 0));
            listOfActiveVertices2.Add(new Vertex(4, 3));
            listOfActiveVertices2.Add(new Vertex(8, 3));
            listOfActiveVertices2.Add(new Vertex(8, 6));
            SSLOperations.SetVertexType(listOfActiveVertices2);
            SSLOperations.ComputeAngleBisectors(listOfActiveVertices2);

            Assert.AreEqual(3.29, Math.Round(listOfActiveVertices2.Get(4).AngleBisector.GetX(), 2));
            Assert.AreEqual(3.71, Math.Round(listOfActiveVertices2.Get(4).AngleBisector.GetY(), 2));
        }
Пример #5
0
        public static void ComputeAngleBisectors(LAV listOfActiveVertices)
        {
            foreach (Vertex v in listOfActiveVertices)
            {
                v.AngleBisector = MathLibrary.GetAngleBisectorVertex(v.PrevLineSegment, v.NextLineSegment);

                if (v.AngleBisector == null)
                {
                    v.AngleBisector = new Vertex(double.PositiveInfinity, double.PositiveInfinity);
                }
                else
                {
                    if (v.Type == Vertex.VertexType.Split)
                    {
                        v.AngleBisector = MathLibrary.Rotate(v, v.AngleBisector, 180);
                    }
                }
            }
        }
Пример #6
0
 public static void GeneratePriorityQueue(LAV listOfActiveVertices)
 {
     foreach (Vertex v in listOfActiveVertices)
         queue.Push(GetClosestIntersection(v));
 }
Пример #7
0
 public static void SetVertexType(LAV listOfActiveVertices)
 {
     foreach (Vertex v in listOfActiveVertices)
     {
         SetVertexType(v);
     }
 }
Пример #8
0
        public void TestQuad()
        {
            SLAV slav = new SLAV();

            //NEED TO MAINTAIN THIS LIST FOR TESTING PURPOSES
            LAV localLav = new LAV();

            Vertex v1 = new Vertex(0, 6);
            Vertex v2 = new Vertex(0, 0);
            Vertex v3 = new Vertex(2, 0);
            Vertex v4 = new Vertex(4, 2);
            Vertex v5 = new Vertex(6, 2);
            Vertex v6 = new Vertex(9, 0);
            Vertex v7 = new Vertex(5, 6);
            Vertex v8 = new Vertex(3.5, 4);
            Vertex v9 = new Vertex(3, 6);

            localLav.Add(v1);
            localLav.Add(v2);
            localLav.Add(v3);
            localLav.Add(v4);
            localLav.Add(v5);
            localLav.Add(v6);
            localLav.Add(v7);
            localLav.Add(v8);
            localLav.Add(v9);

            slav.Insert(v1, 0);
            slav.Insert(v2, 0);
            slav.Insert(v3, 0);
            slav.Insert(v4, 0);
            slav.Insert(v5, 0);
            slav.Insert(v6, 0);
            slav.Insert(v7, 0);
            slav.Insert(v8, 0);
            slav.Insert(v9, 0);

            SSLOperations.SetVertexType(localLav);
            SSLOperations.ComputeAngleBisectors(localLav);

            SSLOperations.SetVertexType(slav.Get(0));
            SSLOperations.ComputeAngleBisectors(slav.Get(0));

            LAV lav = slav.Get(0);
            Assert.AreEqual(v1, lav.Get(1));
            Assert.AreEqual(v2, lav.Get(2));
            Assert.AreEqual(v3, lav.Get(3));
            Assert.AreEqual(v4, lav.Get(4));
            Assert.AreEqual(v5, lav.Get(5));
            Assert.AreEqual(v6, lav.Get(6));
            Assert.AreEqual(v7, lav.Get(7));
            Assert.AreEqual(v8, lav.Get(8));
            Assert.AreEqual(v9, lav.Get(9));

            slav.BreakAndCreateNew(v8, 0);

            lav = slav.Get(0);

            Assert.AreEqual(v1, lav.Get(1));
            Assert.AreEqual(v2, lav.Get(2));
            Assert.AreEqual(v3, lav.Get(3));
            Assert.AreEqual(v4, lav.Get(4));
            Assert.AreEqual(3.30, Math.Round(lav.Get(5).GetX(), 2));
            Assert.AreEqual(3.02, Math.Round(lav.Get(5).GetY(), 2));
            Assert.AreEqual(v9, lav.Get(6));
            Assert.AreEqual(v1, lav.Get(6).GetNextVertex());

            lav = slav.Get(1);

            Assert.AreEqual(3.30, Math.Round(lav.Get(1).GetX(), 2));
            Assert.AreEqual(3.02, Math.Round(lav.Get(1).GetY(), 2));
            Assert.AreEqual(v5, lav.Get(2));
            Assert.AreEqual(v6, lav.Get(3));
            Assert.AreEqual(v7, lav.Get(4));
            Assert.AreEqual(3.30, Math.Round(lav.Get(4).GetNextVertex().GetX(), 2));
        }
Пример #9
0
        protected void SetUp()
        {
            setListOfActiveVertices = new SLAV();
            setListOfActiveVertices.Insert(new Vertex(2, 6), 0);
            setListOfActiveVertices.Insert(new Vertex(2, 2), 0);
            setListOfActiveVertices.Insert(new Vertex(15, 2), 0);
            setListOfActiveVertices.Insert(new Vertex(15, 6), 0);

            listOfActiveVertices = new LAV();
            listOfActiveVertices.Add(new Vertex(2, 6));
            listOfActiveVertices.Add(new Vertex(2, 2));
            listOfActiveVertices.Add(new Vertex(15, 2));
            listOfActiveVertices.Add(new Vertex(15, 6));

            SSLOperations.SetVertexType(setListOfActiveVertices.Get(0));
            SSLOperations.ComputeAngleBisectors(setListOfActiveVertices.Get(0));

            SSLOperations.SetVertexType(listOfActiveVertices);
            SSLOperations.ComputeAngleBisectors(listOfActiveVertices);
        }
Пример #10
0
        public void TestVertexType()
        {
            //ALL CONVEX POLYGONS
            //RECTANGLE
            SSLOperations.SetVertexType(listOfActiveVertices);

            foreach (Vertex v in listOfActiveVertices)
                Assert.AreEqual(Vertex.VertexType.Edge, v.Type);

            //DIAMOND
            LAV listOfActiveVertices2 = new LAV();
            listOfActiveVertices2.Add(new Vertex(2, 4));
            listOfActiveVertices2.Add(new Vertex(0, 2));
            listOfActiveVertices2.Add(new Vertex(2, 0));
            listOfActiveVertices2.Add(new Vertex(4, 2));
            SSLOperations.SetVertexType(listOfActiveVertices2);

            foreach (Vertex v in listOfActiveVertices2)
                Assert.AreEqual(Vertex.VertexType.Edge, v.Type);

            //OCTAGON
            LAV listOfActiveVertices3 = new LAV();
            listOfActiveVertices3.Add(new Vertex(3, 10));
            listOfActiveVertices3.Add(new Vertex(0, 7));
            listOfActiveVertices3.Add(new Vertex(0, 3));
            listOfActiveVertices3.Add(new Vertex(3, 0));
            listOfActiveVertices3.Add(new Vertex(7, 0));
            listOfActiveVertices3.Add(new Vertex(10, 3));
            listOfActiveVertices3.Add(new Vertex(10, 7));
            listOfActiveVertices3.Add(new Vertex(7, 10));
            SSLOperations.SetVertexType(listOfActiveVertices3);

            foreach (Vertex v in listOfActiveVertices3)
                Assert.AreEqual(Vertex.VertexType.Edge, v.Type);

            //ALL NON-CONVEX POLYGONS
            //PEAK -- W type shape
            LAV listOfActiveVertices4 = new LAV();
            listOfActiveVertices4.Add(new Vertex(0, 3));
            listOfActiveVertices4.Add(new Vertex(2, 0));
            listOfActiveVertices4.Add(new Vertex(4, 2));
            listOfActiveVertices4.Add(new Vertex(6, 0));
            listOfActiveVertices4.Add(new Vertex(8, 3));
            SSLOperations.SetVertexType(listOfActiveVertices4);

            for (int i = 0; i < listOfActiveVertices4.Length; i++)
                if (i != 3)
                    Assert.AreEqual(Vertex.VertexType.Edge, listOfActiveVertices4.Get(i).Type);
                else
                    Assert.AreEqual(Vertex.VertexType.Split, listOfActiveVertices4.Get(i).Type);

            //VALLEY
            LAV listOfActiveVertices5 = new LAV();
            listOfActiveVertices5.Add(new Vertex(0, 4));
            listOfActiveVertices5.Add(new Vertex(0, 0));
            listOfActiveVertices5.Add(new Vertex(4, 0));
            listOfActiveVertices5.Add(new Vertex(4, 4));
            listOfActiveVertices5.Add(new Vertex(2, 2));
            SSLOperations.SetVertexType(listOfActiveVertices5);

            for (int i = 0; i < listOfActiveVertices5.Length; i++)
                if (i != 5)
                    Assert.AreEqual(Vertex.VertexType.Edge, listOfActiveVertices5.Get(i).Type);
                else
                    Assert.AreEqual(Vertex.VertexType.Split, listOfActiveVertices5.Get(i).Type);

            //>
            LAV listOfActiveVertices6 = new LAV();
            listOfActiveVertices6.Add(new Vertex(0, 4));
            listOfActiveVertices6.Add(new Vertex(2, 2));
            listOfActiveVertices6.Add(new Vertex(0, 0));
            listOfActiveVertices6.Add(new Vertex(4, 0));
            listOfActiveVertices6.Add(new Vertex(4, 4));
            SSLOperations.SetVertexType(listOfActiveVertices6);

            for (int i = 0; i < listOfActiveVertices6.Length; i++)
                if (i != 2)
                    Assert.AreEqual(Vertex.VertexType.Edge, listOfActiveVertices6.Get(i).Type);
                else
                    Assert.AreEqual(Vertex.VertexType.Split, listOfActiveVertices6.Get(i).Type);

            //<
            LAV listOfActiveVertices7 = new LAV();
            listOfActiveVertices7.Add(new Vertex(0, 4));
            listOfActiveVertices7.Add(new Vertex(0, 0));
            listOfActiveVertices7.Add(new Vertex(4, 0));
            listOfActiveVertices7.Add(new Vertex(2, 2));
            listOfActiveVertices7.Add(new Vertex(4, 4));
            SSLOperations.SetVertexType(listOfActiveVertices7);

            for (int i = 0; i < listOfActiveVertices7.Length; i++)
                if (i != 4)
                    Assert.AreEqual(Vertex.VertexType.Edge, listOfActiveVertices7.Get(i).Type);
                else
                    Assert.AreEqual(Vertex.VertexType.Split, listOfActiveVertices7.Get(i).Type);

            /*
             * X------------------------X
             * |                        |
             * |                        |
             * |            X-----------X
             * |            |
             * |            |
             * X------------X
            */
            LAV listOfActiveVertices8 = new LAV();
            listOfActiveVertices8.Add(new Vertex(0, 6));
            listOfActiveVertices8.Add(new Vertex(0, 0));
            listOfActiveVertices8.Add(new Vertex(4, 0));
            listOfActiveVertices8.Add(new Vertex(4, 3));
            listOfActiveVertices8.Add(new Vertex(8, 3));
            listOfActiveVertices8.Add(new Vertex(8, 6));
            SSLOperations.SetVertexType(listOfActiveVertices8);

            for (int i = 0; i < listOfActiveVertices8.Length; i++)
                if (i != 4)
                    Assert.AreEqual(Vertex.VertexType.Edge, listOfActiveVertices8.Get(i).Type);
                else
                    Assert.AreEqual(Vertex.VertexType.Split, listOfActiveVertices8.Get(i).Type);

            /*
             * X------------------------X
             * |                        |
             * |                        |
             * X------------X           X
             *              |           |
             *              |           |
             *              |           |
             *              X-----------X
            */
            LAV listOfActiveVertices9 = new LAV();
            listOfActiveVertices9.Add(new Vertex(0, 8));
            listOfActiveVertices9.Add(new Vertex(0, 3));
            listOfActiveVertices9.Add(new Vertex(4, 3));
            listOfActiveVertices9.Add(new Vertex(4, 0));
            listOfActiveVertices9.Add(new Vertex(8, 0));
            listOfActiveVertices9.Add(new Vertex(8, 6));
            SSLOperations.SetVertexType(listOfActiveVertices9);

            for (int i = 0; i < listOfActiveVertices9.Length; i++)
                if (i != 3)
                    Assert.AreEqual(Vertex.VertexType.Edge, listOfActiveVertices9.Get(i).Type);
                else
                    Assert.AreEqual(Vertex.VertexType.Split, listOfActiveVertices9.Get(i).Type);
        }
Пример #11
0
        public void TestNoIntersection()
        {
            LAV infiniteLav = new LAV();
            infiniteLav.Add(new Vertex(0, 0));
            infiniteLav.Add(new Vertex(1, 0));
            infiniteLav.Add(new Vertex(2, 0));
            SSLOperations.SetVertexType(infiniteLav);
            SSLOperations.ComputeAngleBisectors(infiniteLav);

            Intersection intersection = SSLOperations.GetClosestIntersection(infiniteLav.GetStart());
            Assert.IsTrue(double.IsInfinity(intersection.Distance));
        }
Пример #12
0
 protected void SetUp()
 {
     listOfActiveVertices = new LAV();
 }