Exemple #1
0
        public static Path3D LoadPath(string file)
        {
            Path3D loadedPath = new Path3D(new List <Point3D>());

            using (StreamReader reader = new StreamReader(file))
            {
                string line = reader.ReadLine();

                const string PointPattern = @"Point [0-9]+ Coordinates { ([0-9]+), ([0-9]+), ([0-9]+) }";

                while (line != null)
                {
                    if (line != "")
                    {
                        MatchCollection matches = Regex.Matches(line, PointPattern);

                        if (matches[0].Groups.Count == 4)
                        {
                            int x = int.Parse(matches[0].Groups[1].Value);
                            int y = int.Parse(matches[0].Groups[2].Value);
                            int z = int.Parse(matches[0].Groups[3].Value);

                            Point3D point = new Point3D(x, y, z);
                            loadedPath.SequenceOfPoints.Add(point);
                        }
                    }

                    line = reader.ReadLine();
                }
            }

            return(loadedPath);
        }
Exemple #2
0
        static void Main()
        {
            var myPath = new Path3D(new List <Point3D>()
            {
                new Point3D(2, 13, 14),
                new Point3D(1, 22, 41),
                new Point3D(5, 23, 43),
                new Point3D(7, 8, 24),
                new Point3D(4, 2, 44),
            });

            //SAVE TO FILE path.txt
            Storage.SavePath("../../path.txt", myPath.ToString());

            //LOAD FROM FILE path.txt
            Console.WriteLine("Loaded path:\r\n" + Storage.LoadPath("../../path.txt"));
        }