static public double CalcDistance(Point3D pointOne, Point3D pointTwo) // Task 3 { double distance; distance = Math.Sqrt(Math.Pow(pointOne.X - pointTwo.X, 2) + Math.Pow(pointOne.Y - pointTwo.Y, 2) + Math.Pow(pointOne.Z - pointTwo.Z, 2)); return distance; }
public static Path LoadPath() // Task 4 { Path loadedPath = new Path(); using (StreamReader pathReader = new StreamReader(@"../../LoadFile.txt")) { string line = pathReader.ReadLine(); while(line != null) { Point3D point = new Point3D(); string[] points = line.Split(','); point.X = double.Parse(points[0]); point.Y = double.Parse(points[1]); point.Z = double.Parse(points[2]); loadedPath.AddPoint(point); line = pathReader.ReadLine(); } } return loadedPath; }
public void AddPoint(Point3D point) // Task 4 { pathPoints.Add(point); }
static void Main(string[] args) // JUST PRESS F5!!! :) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("TEST 1 \"Point3D\":"); Console.ResetColor(); Console.WriteLine(); Point3D A = new Point3D(2, 8, 6); Point3D B = new Point3D(5, 3, 5); Console.WriteLine("Printing Points A and B:"); Console.WriteLine(A); Console.WriteLine(B); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("END TEST 1 \"Point3D\""); Console.WriteLine(); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("TEST 2 \"DistanceFinder\":"); Console.ResetColor(); Console.WriteLine(); Console.Write("Distance: "); Console.WriteLine(DistanceFinder.CalcDistance(A, B)); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("END TEST 2 \"DistanceFinder\""); Console.WriteLine(); Console.ResetColor(); Path newLine = new Path(); newLine.AddPoint(A); newLine.AddPoint(B); newLine.AddPoint(new Point3D(9, 6, 5)); Point3D C = newLine.PathPoints[2]; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("TEST 3 \"Load Points from file\":"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine("Loaded points from file \"LoadFile.txt\":"); Path loadedPath = PathStorage.LoadPath(); foreach (Point3D point in loadedPath.PathPoints) { Console.WriteLine(point); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("END TEST 3 \"Load Points from file\""); Console.WriteLine(); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("TEST 4 \"Save Points to file\":"); Console.ResetColor(); Console.WriteLine(); PathStorage.SavePath(newLine); Console.WriteLine("Points A, B and C are saved in SaveFile.txt"); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("END TEST 4 \"Save Points to file\""); Console.WriteLine(); Console.ResetColor(); GenericList<string> theList = new GenericList<string>(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("TEST 5 \"GenericList\":"); Console.ResetColor(); Console.WriteLine(); theList.AddElement("1"); theList.AddElement("3"); Console.Write("Printed elements from \"TheList\": "); Console.WriteLine(theList); Console.WriteLine(); Console.WriteLine("Adding \"2\" in position 1!"); theList.InsertElement(1, "2"); Console.Write("Printed elements from \"TheList\": "); Console.WriteLine(theList); Console.WriteLine(); Console.WriteLine("Removing element with index 1!"); theList.RemoveElementAtIndex(1); Console.Write("Printed elements from \"TheList\": "); Console.WriteLine(theList); Console.WriteLine(); Console.WriteLine("Clearing \"TheList\"!"); theList.Clear(); Console.Write("Printed elements from \"TheList\": "); Console.WriteLine(theList); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("END TEST 5 \"GenericList\""); Console.WriteLine(); Console.ResetColor(); Console.Write("Press any key to continue..."); Console.ReadLine(); }