public static Path LoadPath() { Path path = new Path(); StreamReader reader = new StreamReader("..\\..\\paths.txt"); using (reader) { string line = reader.ReadLine(); while (line != null) { Point3D point = new Point3D(); string[] pointsArray = line.Split(new char[] { '(', ')', ',' }, StringSplitOptions.RemoveEmptyEntries); point.X = int.Parse(pointsArray[0]); point.Y = int.Parse(pointsArray[1]); point.Z = int.Parse(pointsArray[2]); path.AddPoint(point); line = reader.ReadLine(); } } return path; }
/// <summary> /// Load Paths from predefined directory /// </summary> /// <returns></returns> public static List <Path> LoadPaths() { List <Path> loadedPaths = new List <Path>(); Path currentPath = new Path(); using (StreamReader reader = new StreamReader(filePath)) { while (!reader.EndOfStream) { string[] token = reader.ReadLine() .Split(new char[] { ' ', '.', ',' }, StringSplitOptions.RemoveEmptyEntries); if (token.Length == 3) { int currentX = int.Parse(token[0]); int currentY = int.Parse(token[1]); int currentZ = int.Parse(token[2]); currentPath.AddPoint(currentX, currentY, currentZ); } else { if (currentPath.PointsList.Count > 0) { loadedPaths.Add(currentPath); } currentPath = new Path(); } } //the last path if not added if (currentPath.Count != 0) { loadedPaths.Add(currentPath); } } return(loadedPaths); }
public static Path LoadFromFile(string fileFullPath) { Path result = new Path(); using (StreamReader reader = new StreamReader(fileFullPath)) { string line = reader.ReadLine(); while (line != null) { string[] dimensions = line.Split(new char[] { ' ', ',', '(', ')', 'x', 'y', 'z', '=' }, StringSplitOptions.RemoveEmptyEntries); double x, y, z; if (dimensions.Length == 3 && double.TryParse(dimensions[0], out x) && double.TryParse(dimensions[1], out y) && double.TryParse(dimensions[2], out z)) { result.AddPoint(new Point3D(x, y, z)); } line = reader.ReadLine(); } } return result; }
/// <summary> /// Load Paths from predefined directory /// </summary> /// <returns></returns> public static List<Path> LoadPaths() { List<Path> loadedPaths = new List<Path>(); Path currentPath = new Path(); using (StreamReader reader = new StreamReader(filePath)) { while (!reader.EndOfStream) { string[] token = reader.ReadLine() .Split(new char[] { ' ', '.', ',' }, StringSplitOptions.RemoveEmptyEntries); if (token.Length == 3) { int currentX = int.Parse(token[0]); int currentY = int.Parse(token[1]); int currentZ = int.Parse(token[2]); currentPath.AddPoint(currentX, currentY, currentZ); } else { if (currentPath.PointsList.Count > 0) { loadedPaths.Add(currentPath); } currentPath = new Path(); } } //the last path if not added if (currentPath.Count != 0) { loadedPaths.Add(currentPath); } } return loadedPaths; }
public static Path LoadPath(string filePath) { Path path = new Path(); try { StreamReader reader = new StreamReader(filePath); using (reader) { string line = reader.ReadLine(); while (line != null) { string[] lineArray = line.Split(' '); path.AddPoint(new Point(int.Parse(lineArray[0]), int.Parse(lineArray[1]), int.Parse(lineArray[2]))); line = reader.ReadLine(); } } } catch (FileNotFoundException notFoundEx) { Console.WriteLine(notFoundEx.Message); } return path; }
public static Path LoadFromFile(string fileFullPath) { Path result = new Path(); using (StreamReader reader = new StreamReader(fileFullPath)) { string line = reader.ReadLine(); while (line != null) { string[] dimensions = line.Split(new char[] { ' ', ',', '(', ')', 'x', 'y', 'z', '=' }, StringSplitOptions.RemoveEmptyEntries); double x, y, z; if (dimensions.Length == 3 && double.TryParse(dimensions[0], out x) && double.TryParse(dimensions[1], out y) && double.TryParse(dimensions[2], out z)) { result.AddPoint(new Point3D(x, y, z)); } line = reader.ReadLine(); } } return(result); }
static void Main() { // testing points Point3D firstPoint = Point3D.CoordinateSystemCenter; Point3D seconPoint = new Point3D(1, 2, 1); Console.WriteLine("First point -> " + firstPoint); Console.WriteLine("Second point -> " + seconPoint); Console.WriteLine("Distance between the two points -> " + DistanceBetweenPoints.CaclculateDistance(firstPoint, seconPoint)); Path myPath = new Path(5); myPath.AddPoint(firstPoint); myPath.AddPoint(firstPoint); myPath.AddPoint(new Point3D(3, 6, 1.5)); myPath.AddPoint(firstPoint); myPath.AddPoint(seconPoint); myPath.AddPoint(firstPoint); myPath.AddPoint(seconPoint); myPath.RemovePoint(seconPoint); myPath.RemovePointAt(1); PathStorage.SaveToFile(myPath,null); Path otherPath = PathStorage.LoadFromFile("../../test.txt"); otherPath.RemovePoint(firstPoint); PathStorage.SaveToFile(otherPath, "text.txt"); }