Example #1
0
        public static void Main(string[] args)
        {
            Point top = new Point(1, 100, 1);
            Console.WriteLine(top);

            Point zero = Point.ZeroPoint;
            Console.WriteLine(zero);

            Point thirth = new Point(1, 1, 200);
            Console.WriteLine(thirth);
            Console.WriteLine();

            Console.WriteLine("-------------Old Path----------");
            var path = new Path(top);
            path.Add(zero);
            path.Add(thirth);
            Print(path.Points);

            PathStorage.Save("path.txt", path);

            Console.WriteLine();
            var newPath = PathStorage.Load("path.txt");
            Console.WriteLine("--------New Path----------------");
            Print(newPath.Points);
        }
        public static Path LoadPath(string filename)
        {
            Path path = new Path();
            try
            {
                var reader = new StreamReader(filename);

                string line = reader.ReadLine();

                while (line != null)
                {
                    path.Add(TryParse(line));

                    line = reader.ReadLine();
                }
                return path;
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File could not be found");
                return null;
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Parsing from file failed!");
                return null;
            }
            catch (Exception)
            {
                Console.WriteLine("Unknown error");
                return null;
            }
        }
Example #3
0
        public static Path Load(string file)
        {
            StreamReader reader = new StreamReader(file);
            Path path = new Path();
            using (reader)
            {
                string line = reader.ReadLine();

                while (line != null)
                {
                    string[] cordinates = line.Split(new char[] { ',' });
                    if (cordinates.Length != 3)
                    {
                        throw new ArgumentOutOfRangeException();
                    }

                    Point newPoint = new Point(
                                               float.Parse(cordinates[0]),
                                               float.Parse(cordinates[1]),
                                               float.Parse(cordinates[2]));
                    path.Add(newPoint);

                    line = reader.ReadLine();
                }
            }

            return path;
        }
        public static void Load(Path path)
        {
            try
            {
                using (StreamReader load = new StreamReader(@"..\..\ListOfPoints.txt"))
                {
                    string line = load.ReadLine();

                    while (line != null)
                    {
                        int firstCommaIndex = line.IndexOf(',');
                        int secondCommaIndex = line.IndexOf(',', firstCommaIndex + 1);
                        double x = double.Parse(line.Substring(2, firstCommaIndex - 2));
                        double y = double.Parse(line.Substring(firstCommaIndex + 2, secondCommaIndex - firstCommaIndex - 2));
                        double z = double.Parse(line.Substring(secondCommaIndex + 2, line.Length - secondCommaIndex - 4));
                        Point3D point = new Point3D(x, y, z);
                        path.Add(point);

                        line = load.ReadLine();
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("There was a problem loading the path file.");
            }
        }
        public static void Main(string[] args)
        {
            Path p = new Path();
            p.Add(new Point3D(1, 2, 3));
            p.Add(new Point3D(2, 2, 2));

            PathStorage.SavePath(p, "path1.txt");

            Path p2 = PathStorage.LoadPath("path1.txt");

            if (p2 != null)
            {
                for (int i = 0; i < p2.Count; i++)
                {
                    Console.WriteLine(p2[i]);
                }

                Console.WriteLine("Distance: ");
                Console.WriteLine(Distance.FindDistance(p2[0], p2[1]));
            }
        }