public SortedPosList Clone() { SortedPosList newInst = new SortedPosList(); newInst.PositionList = new List <Position>(); for (int i = 0; i < PositionList.Count; i++) { newInst.Add(PositionList[i].Clone()); } return(newInst); }
public SortedPosList ReadFileToSortedList() { string[] lines = System.IO.File.ReadAllLines(FILEPATH); SortedPosList nList = new SortedPosList(); for (int i = 0; i < lines.Length; i++) { nList.Add(StringToPosition(lines[i])); } return(nList); }
public SortedPosList CircleContent(Position position, double radius) { SortedPosList newInst = new SortedPosList(); newInst.PositionList = new List <Position>(); for (int i = 0; i < PositionList.Count; i++) { if (InCircle(position, radius, i)) { newInst.Add(PositionList[i]); } } return(newInst); }
public void SavePositionToFile(Position p) { SortedPosList readList = ReadFileToSortedList(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(FILEPATH)) { string temp = ToString(); for (int i = 0; i < readList.Count(); i++) { file.WriteLine(readList.PositionList[i].ToString()); } file.WriteLine(p.ToString()); } }
protected static void Main(string[] args) { Console.WriteLine(new Position(2, 4) + new Position(1, 2) + " : plus Operator on pos\n"); Console.WriteLine(new Position(2, 4) - new Position(1, 2) + " : minus Operator on pos\n"); Console.WriteLine(new Position(1, 2) - new Position(3, 6) + " : minus Operator on pos\n"); Console.WriteLine(new Position(3, 5) % new Position(1, 3) + " : modulos operator on pos\n"); Console.WriteLine(new Position(5, 3) < new Position(3, 10)); SortedPosList list1 = new SortedPosList(FILEPATH); SortedPosList list2 = new SortedPosList(FILEPATH); 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 + " : First List\n"); list1.Remove(new Position(2, 6)); Console.WriteLine(list1 + " : Remove from first List\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)); list2.Add(new Position(2, 3)); Console.WriteLine((list2 + list1) + " : Plus \n"); Console.WriteLine(list1 + " : First\n"); Console.WriteLine(list2 + " : Second\n"); Console.WriteLine((list2 - list1) + " : Minus \n"); SortedPosList circleList = new SortedPosList(FILEPATH); circleList.Add(new Position(1, 1)); circleList.Add(new Position(2, 2)); circleList.Add(new Position(3, 3)); Console.WriteLine(circleList + " : CircleList\n"); Console.WriteLine(circleList.CircleContent(new Position(5, 5), 4) + " : Inside Circle \n"); // list1.WriteToFile(); Console.WriteLine(list1.ReadFileToSortedList() + " : File"); }
public static SortedPosList operator +(SortedPosList p1, SortedPosList p2) { SortedPosList newList = new SortedPosList(); int size = p1.Count(); if (p1.Count() <= p2.Count()) { size = p2.Count(); } for (int i = 0; i < size; i++) { if (i < p1.Count()) { newList.Add(p1.PositionList[i].Clone()); } if (i < p2.Count()) { newList.Add(p2.PositionList[i].Clone()); } } // operator stuff return(newList); }