コード例 #1
0
        public static Path Load(string filePath)
        {
            Path path = new Path();
            try
            {
                using (StreamReader file = new StreamReader(filePath))
                {
                    string line;
                    while((line = file.ReadLine()) != String.Empty && line != null)
                    {
                        try
                        {
                            double[] coords = Array.ConvertAll<string, double>(line.Substring(line.IndexOf("{") + 1).Split(new char[]{';','}'}, StringSplitOptions.RemoveEmptyEntries), double.Parse);
                            Point3D point = new Point3D(coords[0], coords[1], coords[2]);
                            path.AddPoint(point);
                        }
                        catch
                        {
                            throw new FormatException(String.Format("Invalid format of coordinates in the file {0}", filePath));
                        }

                    }
                }
            }
            catch(FileNotFoundException)
            {
                throw new FileNotFoundException("File {0} not found", filePath);
            }
            return path;
        }
コード例 #2
0
 public static Path LoadPathFromFile(string file)
 {
     Path path3D = new Path();
     string[] pointsFromText = File.ReadAllText(file).Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
     
     for (int i = 0; i < pointsFromText.Length; i++)
     {
         string[] coordinates = pointsFromText[i].Split(Separators, StringSplitOptions.RemoveEmptyEntries).ToArray();
         
         path3D.AddPoint(new Point3D( double.Parse(coordinates[1]), double.Parse(coordinates[3]), double.Parse(coordinates[5])));
     }
         
     return path3D;
 }
コード例 #3
0
        public static Path LoadPath(string filePath)
        {
            var path = new Path();
            using (var reader = new StreamReader(filePath))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    Point3D point = Point3D.Parse(line);
                    path.AddPoint(point);
                }
            }

            return path;
        }