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"); }
public static SortedPosList operator +(SortedPosList sp1, SortedPosList sp2) { SortedPosList addedList = new SortedPosList(); foreach (Position p1 in sp1) { addedList.Add(p1.Clone()); } foreach (Position p2 in sp2) { addedList.Add(p2.Clone()); } return(addedList); }
public SortedPosList Clone() { SortedPosList clonedList = new SortedPosList(); foreach (Position p in PositionList) { clonedList.Add(p.Clone()); } return(clonedList); }
public SortedPosList CircleContent(Position centerPos, double radius) { SortedPosList circledList = new SortedPosList(); foreach (Position p in PositionList) { bool insideCircle = (Math.Pow(p.Xpos - centerPos.Xpos, 2) + Math.Pow(p.Ypos - centerPos.Ypos, 2)) < Math.Pow(radius, 2); if (insideCircle) { circledList.Add(p.Clone()); } } return(circledList); }
public static SortedPosList operator -(SortedPosList sp1, SortedPosList sp2) { SortedPosList subList = new SortedPosList(); foreach (Position p1 in sp1) { subList.Add(p1); foreach (Position p2 in sp2) { if (p1.Equals(p2)) { subList.Remove(p1); } } } return(subList); }