/*
         *      Test file.
         *
                ../../PathSave.txt
         */
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            // Create Path
            Path path = new Path();

            // Fill path with points
            path.AddPoint(Point3D.O);
            path.AddPoint(new Point3D(2, 4, 6));
            path.AddPoint(new Point3D(1, -2, 8));
            path.AddPoint(new Point3D(2.2, 4.0, 16));
            path.AddPoint(new Point3D(45, 8, 0.0));
            path.AddPoint(new Point3D(0, 3.5, 5));
            path.AddPoint(new Point3D(3, 45, 6.5445));

            // Print count and contents of path
            Console.WriteLine("Count: {0}", path.Count);

            foreach (Point3D point in path.ThePath)
            {
                Console.WriteLine(point.ToString());
            }

            // Test Saving
            PathStorage.SavePath(path);

            // Test Clearing
            path.ClearPath();

            Console.WriteLine("Count: {0}", path.Count);

            // Test Loading
            path = PathStorage.LoadPath();

            Console.WriteLine("Count: {0}", path.Count);

            foreach (Point3D point in path.ThePath)
            {
                Console.WriteLine(point.ToString());
            }

            // Test distance between points
            Point3D point1 = new Point3D(4,8,3);
            Point3D point2 = new Point3D(6,3,10);

            Console.WriteLine("Distance between {0} and {1}: {2}",
                point1.ToString(), point2.ToString(), Distance3D.Distance(point1, point2));

            /*
             * Expected result: 8.83176086632785
             */
        }
        public static Path LoadPath()
        {
            Console.WriteLine("Input full path to a text file containing a Path:");
            string filePath = Console.ReadLine();

            Path newPath = new Path();

            try
            {
                StreamReader reader = new StreamReader(filePath);

                using (reader)
                {
                    while (!reader.EndOfStream)
                    {
                        string[] strCoords = reader.ReadLine().Split(' ');

                        double[] coords = new double[strCoords.Length];
                        for (int i = 0; i < strCoords.Length; i++)
                        {
                            coords[i] = double.Parse(strCoords[i]);
                        }

                        newPath.AddPoint(new Point3D(coords[0], coords[1], coords[2]));
                    }
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Incorrect file path was entered.");
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("The entered directory wasn't found.");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("The file wasn't found.");
            }
            catch (IOException)
            {
                Console.WriteLine("An Error occured while trying to read the file.");
            }
            catch (Exception)
            {
                Console.WriteLine("An error occured while trying to load a Path.");
            }

            return newPath;
        }