Пример #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine(new Position(2, 4) + new Position(1, 2) + "\n");
            Console.WriteLine(new Position(2, 4) - new Position(1, 2) + "\n");
            Console.WriteLine(new Position(1, 2) - new Position(3, 6) + "\n"); // Negative value. returns: (0,0)
            Console.WriteLine(new Position(3, 5) % new Position(1, 3) + "\n");

            SortedPosList list1 = new SortedPosList();
            SortedPosList list2 = new SortedPosList();

            list1.Add(new Position(3, 7));
            list1.Add(new Position(1, 4));
            list1.Add(new Position(2, 6));
            list1.Add(new Position(2, 3));
            Console.WriteLine(list1 + "\n");
            list1.Remove(new Position(2, 6));
            Console.WriteLine(list1 + "\n");

            list2.Add(new Position(3, 7));
            list2.Add(new Position(1, 2));
            list2.Add(new Position(3, 6));
            list2.Add(new Position(2, 3));
            Console.WriteLine((list2 + list1) + "\n");

            SortedPosList circleList = new SortedPosList();

            circleList.Add(new Position(1, 1));
            circleList.Add(new Position(2, 2));
            circleList.Add(new Position(3, 3));
            Console.WriteLine(circleList.CircleContent(new Position(5, 5), 4) + "\n");

            Console.WriteLine("Thank you. Bye, bye");
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine(new Position(2, 4) + new Position(1, 2) + "\n");
            Console.WriteLine(new Position(2, 4) - new Position(1, 2) + "\n");
            Console.WriteLine(new Position(1, 2) - new Position(3, 6) + "\n");
            Console.WriteLine(new Position(3, 5) % new Position(1, 3) + "\n");

            SortedPosList list1 = new SortedPosList();
            SortedPosList list2 = new SortedPosList();

            list1.Add(new Position(3, 7));
            list1.Add(new Position(1, 4));
            list1.Add(new Position(2, 6));
            list1.Add(new Position(2, 3));
            Console.WriteLine(list1 + "\n");
            list1.Remove(new Position(2, 6));
            Console.WriteLine(list1 + "\n");

            list2.Add(new Position(3, 7));
            list2.Add(new Position(1, 2));
            list2.Add(new Position(3, 6));
            list2.Add(new Position(2, 3));
            Console.WriteLine((list2 + list1) + "\n");

            SortedPosList circleList = new SortedPosList();

            circleList.Add(new Position(1, 1));
            circleList.Add(new Position(2, 2));
            circleList.Add(new Position(3, 3));
            Console.WriteLine(circleList.CircleContent(new Position(5, 5), 4) + "\n");
        }
Пример #3
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());
            }
        }
Пример #4
0
        public SortedPosList Clone()
        {
            SortedPosList clonedList = new SortedPosList();

            for (int i = 0; i < positionList.Count; i++)
            {
                clonedList.Add(positionList[i].Clone());
            }
            return(clonedList);
        }
Пример #5
0
        public static SortedPosList operator +(SortedPosList sp1, SortedPosList sp2)
        {
            SortedPosList clonedList = sp1.Clone();

            for (int i = 0; i < sp2.Count(); i++)
            {
                clonedList.Add(sp2[i].Clone());
            }
            return(clonedList);
        }
Пример #6
0
        public SortedPosList Clone()
        {
            SortedPosList newList = new SortedPosList();

            for (int i = 0; i < posList.Count(); i++)
            {
                newList.Add(posList[i].Clone());
            }
            return(newList);
        }
        public static SortedPosList operator +(SortedPosList sp1, SortedPosList sp2)
        {
            SortedPosList result = sp1.Clone();

            for (var i = 0; i < sp2.Count(); i++)
            {
                result.Add(sp2[i]);
            }

            return(result);
        }
Пример #8
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());
            }
        }
Пример #9
0
        public SortedPosList CircleContent(Position centerPos, double radius)
        {
            SortedPosList circleList = new SortedPosList();

            for (int i = 0; i < positionList.Count; i++)
            {
                double diameter   = Math.Pow(positionList[i].X - centerPos.X, 2) + Math.Pow(positionList[i].Y - centerPos.Y, 2);
                double squareRoot = Math.Pow(radius, 2);

                if (diameter < squareRoot)
                {
                    circleList.Add(positionList[i].Clone());
                }
            }
            return(circleList);
        }
Пример #10
0
        public SortedPosList CircleContent(Position centerPos, double radius)
        {
            SortedPosList newList = new SortedPosList();

            for (int i = 0; i < posList.Count(); i++)
            {
                double d   = Math.Pow(posList[i].X - centerPos.X, 2) + Math.Pow(posList[i].Y - centerPos.Y, 2);
                double sqR = Math.Pow(radius, 2);

                if (d < sqR)
                {
                    Console.WriteLine("INSIDE CIRCLE. d :" + d + "  sqR: " + sqR);
                    newList.Add(posList[i].Clone());
                }
            }
            return(newList);
        }
        static void Main(string[] args)
        {
            Console.WriteLine(new Position(2, 4) + new Position(1, 2) + "\n");
            Console.WriteLine(new Position(2, 4) - new Position(1, 2) + "\n");
            Console.WriteLine(new Position(1, 2) - new Position(3, 6) + "\n");
            Console.WriteLine(new Position(3, 5) % new Position(1, 3) + "\n");
            Console.WriteLine(new Position(10, 15).Equals(new Position(10, 15)) + "\n");
            Console.WriteLine(new Position(10, 15).Equals(new Position(3, 15)) + "\n");

            SortedPosList list1 = new SortedPosList();
            SortedPosList list2 = new SortedPosList();

            list1.Add(new Position(3, 7));
            list1.Add(new Position(1, 4));
            list1.Add(new Position(2, 6));
            list1.Add(new Position(2, 3));
            Console.WriteLine(list1 + "\n");
            list1.Remove(new Position(2, 6));
            Console.WriteLine(list1 + "\n");

            list2.Add(new Position(3, 7));
            list2.Add(new Position(1, 2));
            list2.Add(new Position(3, 6));
            list2.Add(new Position(2, 3));
            Console.WriteLine((list2 + list1) + "\n");

            SortedPosList circleList = new SortedPosList();

            circleList.Add(new Position(1, 1));
            circleList.Add(new Position(2, 2));
            circleList.Add(new Position(3, 3));
            Console.WriteLine(circleList.CircleContent(new Position(5, 5), 4) + "\n");



            // Create positions and SortedPosLists, add positions and use the ^ operator

            Position p1  = new Position(1, 2);
            Position p2  = new Position(4, 2);
            Position p3  = new Position(2, 2);
            Position p4  = new Position(6, 2);
            Position p5  = new Position(1, 2);
            Position p6  = new Position(1, 8);
            Position p7  = new Position(2, 2);
            Position p8  = new Position(2, 6);
            Position p9  = new Position(1, 1);
            Position p10 = new Position(1, 1);

            SortedPosList s1 = new SortedPosList();

            s1.Add(p1);
            s1.Add(p2);
            s1.Add(p3);
            s1.Add(p4);
            s1.Add(p9);
            SortedPosList s2 = new SortedPosList();

            s2.Add(p5);
            s2.Add(p6);
            s2.Add(p7);
            s2.Add(p8);
            s2.Add(p10);

            Console.WriteLine(s1);
            Console.WriteLine(s2);
            Console.WriteLine(s1 ^ s2);



            // Create SortedPosList with path and sync with file

            string path = "/Users/canon/Google Drive/ITHS 2017 JH Drive/C SHARP/lab2/positionFiles/test.txt";

            SortedPosList s3 = new SortedPosList(path);

            s3.Add(new Position(2, 2));
            s3.Add(new Position(3, 2));
            Console.WriteLine(s3);
        }