예제 #1
0
        public static Path3D LoadPathFromFile(string filepath)
        {
            Path3D path = new Path3D();

            using (StreamReader reader = new StreamReader(filepath))
            {
                string       line         = reader.ReadLine();
                const string PointPattern = @"[xyz=:\-\s](\d+(?:(?:\.|,)\d+)*)";

                while (line != null)
                {
                    MatchCollection matches = Regex.Matches(line, PointPattern);
                    if (matches.Count == 3)
                    {
                        double x = double.Parse(matches[0].Groups[1].Value);
                        double y = double.Parse(matches[1].Groups[1].Value);
                        double z = double.Parse(matches[2].Groups[1].Value);

                        Point3D point = new Point3D(x, y, z);
                        path.AddPoints(point);
                    }

                    line = reader.ReadLine();
                }
            }
            return(path);
        }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                Point3D point1 = new Point3D(0, 5, 1);
                Point3D point2 = new Point3D(-3, 20, 0);
                Path3D  path   = new Path3D(point1, point2);

                Storage.SavePathToFile("../../path.txt", path.ToString());
                Console.WriteLine("Load from file:\n" + Storage.LoadPathFromFile("../../path.txt"));
            }
            catch (Exception)
            {
                throw;
            }
        }