static void Main() { List<_3DPoint> sequenceOfPoints = new List<_3DPoint>(); sequenceOfPoints.Add(_3DPoint.StartingPoint); sequenceOfPoints.Add(new _3DPoint(0, 1, 2)); sequenceOfPoints.Add(new _3DPoint(1.5, -3.4, 0)); sequenceOfPoints.Add(new _3DPoint(-3.1, 0, 4)); Path3d path = new Path3d(sequenceOfPoints); path.AddPointToPath(new _3DPoint(0, -1, 1.1111)); Console.WriteLine(path); string fileLocation = "Path3d.txt"; Storage.SavePathToFile(fileLocation, path); Path3d pathFromFile = Storage.LoadPathFromFile(fileLocation); Console.WriteLine(pathFromFile); }
public static Path3d LoadPathFromFile(string fileLocation) { string input = File.ReadAllText(fileLocation); if (!Regex.IsMatch(input, PathMatcher)) { throw new ArgumentNullException("input", "File does not contain Path3D data."); } string pathAsString = Regex.Match(input, PathMatcher).Groups[1].Value; var pointsInPath = new List<_3DPoint>(); foreach (Match match in Regex.Matches(pathAsString, PointMatcher)) { double xCoordinate = double.Parse(match.Groups[1].Value); double yCoordinate = double.Parse(match.Groups[2].Value); double zCoordinate = double.Parse(match.Groups[3].Value); pointsInPath.Add(new _3DPoint(xCoordinate, yCoordinate, zCoordinate)); } Path3d pathFromFile = new Path3d(pointsInPath); return pathFromFile; }
public static void SavePathToFile(string fileLocation, Path3d path) { File.WriteAllText(fileLocation, path.ToString()); }