private static string[] ParseToStringList(SortedPosList list)
        {
            string[] content = new string[list.Count()];

            for (var i = 0; i < list.Count(); i++)
            {
                content[i] = list[i].ToString();
            }

            return(content);
        }
        // VS ser "•" som "unexpected character" så jag använder "^" istället
        // Hade gärna använt Except() här men eftersom PositionList endast får användas inom klassen så går ju inte det.

        public static SortedPosList operator ^(SortedPosList sp1, SortedPosList sp2)
        {
            SortedPosList result    = sp1.Clone();
            int           indexA    = 0;
            int           indexB    = 0;
            bool          endOfList = false;


            while (!endOfList)
            {
                Position a = result[indexA];
                Position b = sp2[indexB];


                if (PositionsEquals(a, b))
                {
                    result.Remove(result[indexA]);
                    indexB++;
                }
                else if (a < b)
                {
                    indexA++;
                }
                else
                {
                    indexB++;
                }
                endOfList |= (indexA == result.Count() || indexB == sp2.Count());
            }
            return(result);
        }
Пример #3
0
        private static void pathTest()
        {
            SortedPosList broList = new SortedPosList(@"/Users/Kakashi/desktop/hello");
            Position      posM    = new Position(123, 37);
            Position      posN    = new Position(14, 55);
            Position      posK    = new Position(3, 69);

            broList.Add(posM);
            broList.Add(posN);
            broList.Add(posK);

            Console.WriteLine("List with path: ");
            for (int i = 0; i < broList.Count(); i++)
            {
                Console.WriteLine(broList[i].ToString());
            }
            broList.Remove(posM);
            Console.WriteLine("List with path after remove: ");
            for (int i = 0; i < broList.Count(); i++)
            {
                Console.WriteLine(broList[i].ToString());
            }

            //List without path bro set
            SortedPosList cousinList = new SortedPosList();
            Position      poss       = new Position(100, 100);

            cousinList.Add(new Position(110, 900));
            cousinList.Add(new Position(50, 10));
            cousinList.Add(poss);
            cousinList.Remove(poss);

            Console.WriteLine("Without Path: ");

            for (int i = 0; i < cousinList.Count(); i++)
            {
                Console.WriteLine(cousinList[i].ToString());
            }
        }
Пример #4
0
        private static void broTest()
        {
            //Egna tester. Operatorer
            Position pos1 = new Position(47, 14);
            Position pos2 = new Position(10, 18);
            Position pos3 = new Position(80, 64);
            Position pos4 = new Position(12, 5);
            Position pos5 = new Position(52, 14);

            Position pos6  = new Position(90, 14);
            Position pos7  = new Position(10, 18);
            Position pos8  = new Position(80, 64);
            Position pos9  = new Position(122, 5);
            Position pos10 = new Position(13, 14);


            SortedPosList habibiList = new SortedPosList();

            habibiList.Add(pos1);
            habibiList.Add(pos2);
            habibiList.Add(pos3);
            habibiList.Add(pos4);
            habibiList.Add(pos5);

            SortedPosList habibtiList = new SortedPosList();

            habibtiList.Add(pos6);
            habibtiList.Add(pos7);
            habibtiList.Add(pos8);
            habibtiList.Add(pos9);
            habibtiList.Add(pos10);

            SortedPosList list3 = habibiList - habibtiList;
            SortedPosList list4 = habibtiList + habibiList;

            habibiList.Remove(new Position(80, 64));
            habibiList.Remove(new Position(10, 11));

            // skriver ut habib - habibiti
            Console.WriteLine("list - list2 : ");
            for (int i = 0; i < list3.Count(); i++)
            {
                Console.WriteLine(list3[i].ToString() + ". Length: " + list3[i].Length());
            }
            Console.WriteLine("list2 + list : ");
            for (int i = 0; i < list4.Count(); i++)
            {
                Console.WriteLine(list4[i].ToString() + ". Length list 2 : " + list4[i].Length());
            }
        }
        public SortedPosList CircleContent(Position centerPos, double radius)
        {
            SortedPosList s = Clone();

            for (var i = 0; i < s.Count(); i++)
            {
                double x = (s[i].X - centerPos.X) * (s[i].X - centerPos.X);
                double y = (s[i].Y - centerPos.Y) * (s[i].Y - centerPos.Y);
                if (x + y >= radius * radius)
                {
                    s.Remove(s[i]);
                }
            }
            return(s);
        }