static void Main(string[] args) { Point3D start = Point3D.StartingCoords; Point3D a = new Point3D(1, 1, 1); Point3D b = new Point3D(2, 2, 3); double distanceStartA = DistanceCalculator.CalculateTheDistance(start, a); double distanceStartB = DistanceCalculator.CalculateTheDistance(start, b); Path3D first = new Path3D(start, a); Path3D second = new Path3D(start, a, b); Storage.SavePath(first, "pathFirst.txt"); Storage.SavePath(second, "pathSecond.txt"); try { Path3D loadedFirst = Storage.LoadPath("pathFirst.txt"); foreach (Point3D point in loadedFirst.Points) { Console.WriteLine("{0} {1} {2}", point.X, point.Y, point.Z); } } catch (FileNotFoundException e) { Console.WriteLine(e.Message); } }
public static Path3D LoadPath(String filename) { List <Point3D> points = new List <Point3D>(); StreamReader reader = new StreamReader(filename); using (reader) { while (true) { String line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } int[] coordinates = line.Split(' ').Select(int.Parse).ToArray(); int x = coordinates[0]; int y = coordinates[1]; int z = coordinates[2]; points.Add(new Point3D(x, y, z)); } } Path3D path = new Path3D(points.ToArray()); return(path); }
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(y, z, x); path.AddPoints(point); } line = reader.ReadLine(); } } return path; }
public static void Main() { Point3D point1 = new Point3D(5, 1, 0); Point3D point2 = new Point3D(20, 0, -3); Path3D path = new Path3D(point1, point2); Storage.SavePathToFile("path.txt", path.ToString()); Console.WriteLine("Load from file:\n" + Storage.LoadPathFromFile("path.txt")); }
public static void SavePath(Path3D path, String filePath) { Stream file = File.Create(filePath); StreamWriter writer = new StreamWriter(file); using (writer) { foreach (Point3D point in path.Points) { writer.WriteLine("{0} {1} {2}", point.X, point.Y, point.Z); } } }
static void Main(string[] args) { Point3D point1 = new Point3D(3, 7, 6); Point3D point2 = new Point3D(2, 3, 2); Point3D point3 = new Point3D(4, 4, 3); Path3D.AddToList(point1); Path3D.AddToList(point2); Path3D list = new Path3D(); Storage.SaveInFile("text.txt"); Storage.LoadFromFile("text.txt"); }