Ejemplo n.º 1
0
        static void Main()
        {
            Path3D  path  = new Path3D();
            Point3D point = new Point3D(2, 5.2, 9.1);

            path.Add(point);
            path.Add(Point3D.StartingPointOfCoordSystem);
            path.Add(new Point3D(2.4, 1.2, 5.3));
            Console.WriteLine("Path saved to a file");
            Console.WriteLine(path);
            Storage.SavePathToATextFile(path);
            var    newPath            = Storage.LoadPathFromAtextFile("../../fileWithAPath.txt");
            Path3D pathLoadedFromFile = newPath;

            Console.WriteLine("Path loaded from file: ");
            Console.WriteLine(newPath.ToString());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Path3D points      = new Path3D();
            var    firsPoint   = new Point3D(5, 6, 7);
            var    secondPoint = new Point3D(12, 7, 9);
            var    thirdPoint  = new Point3D(3, 32, 15);
            var    fourthPoint = new Point3D(35, 68, 14);
            var    fifthPoint  = new Point3D(45, 61, 93);

            points.Add(firsPoint);
            points.Add(secondPoint);
            points.Add(thirdPoint);
            points.Add(fourthPoint);
            points.Add(fifthPoint);

            Storage.Save("exportedPoints", points);

            Path3D loadedPoints = Storage.Load("exportedPoints");

            foreach (var point in loadedPoints.Points)
            {
                Console.WriteLine(point);
            }
        }
Ejemplo n.º 3
0
        public static Path3D Load(string file)
        {
            Path3D loadedPath = new Path3D();

            using (StreamReader reader = new StreamReader("../../" + file + ".txt"))
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    string[] currLine = line.Split(' ', '(', ')', ',');
                    int      x        = int.Parse(currLine[1]);
                    int      y        = int.Parse(currLine[3]);
                    int      z        = int.Parse(currLine[5]);
                    loadedPath.Add(new Point3D(x, y, z));

                    line = reader.ReadLine();
                }
            }

            return(loadedPath);
        }
Ejemplo n.º 4
0
        public static Path3D LoadPathFromAtextFile(string filePath)
        {
            Path3D path = new Path3D();

            using (var reader = new StreamReader(filePath))
            {
                string line    = reader.ReadLine();
                string pattern = @"X: (\-?[0-9]+\.?[0-9]*), Y: (\-?[0-9]+\.?[0-9]*), Z: (\-?[0-9]+\.?[0-9]*)";
                Regex  regex   = new Regex(pattern);
                while (line != null)
                {
                    Match match = regex.Match(line);
                    if (match.Success)
                    {
                        Point3D point = new Point3D(double.Parse(match.Groups[1].ToString()), double.Parse(match.Groups[2].ToString()),
                                                    double.Parse(match.Groups[3].ToString()));
                        path.Add(point);
                    }
                    line = reader.ReadLine();
                }
            }

            return(path);
        }