static void Main() { Point3D myPoint = new Point3D(1, 2, 3); Console.WriteLine("The ToString() overload: {0}", myPoint); Console.WriteLine(); Console.WriteLine("The static point 0: {0}", Point3D.CentrePoint); Console.WriteLine(); Point3D myOtherPoint = new Point3D(3, 2, 1); double pointsDistance = CalculateDistance.Distance(myPoint, myOtherPoint); Console.WriteLine("Calculated distance: {0}", pointsDistance); Console.WriteLine(); Path route = new Path(); route.AddPoint(Point3D.CentrePoint); route.AddPoint(myPoint); route.AddPoint(myOtherPoint); route.AddPoint(new Point3D(1.1, 2.2, 3.82743658793465)); Console.WriteLine("One of the points in the path: {0}", route.PointsPath[1]); Console.WriteLine(); PathStorage.SavePath(route, "../../test.txt"); Path loadedRoute = PathStorage.LoadPath("../../test.txt"); Console.WriteLine("Print path loaded from file"); foreach (var point in loadedRoute.PointsPath) { Console.WriteLine(point); } }
static void Main() { Point3D p1 = new Point3D(1, 2, 3); Point3D p2 = new Point3D(4, 5, 6); Console.WriteLine("Distance between ({0}) and ({1}) = {2}", p1, p2, Distance.Calculate(p1, p2)); Path path = new Path(); path.AddPoint(p1); path.AddPoint(p2); PathStorage.Save(path, @"../../pointList.txt"); PathStorage.Load(@"../../pointList.txt"); }
public static Path LoadPath(string name) { Path filePath = new Path(); string fullPath = Text.Path.Combine("..\\..\\Paths", String.Format("{0}.txt", name.Trim())); try { var reader = new Text.StreamReader(fullPath); using (reader) { var points = reader.ReadToEnd().Split(new string[] {"-"}, StringSplitOptions.RemoveEmptyEntries); foreach (var point in points) { var coordinates = point.Trim('{').Trim('}').Split(new char[] {' ', ','}, StringSplitOptions.RemoveEmptyEntries).ToArray(); var newPoint = new Point3D(double.Parse(coordinates[0]), double.Parse(coordinates[1]), double.Parse(coordinates[2])); filePath.AddPoint(newPoint); } } } catch (Exception e) { Console.WriteLine(e.Message); return null; } return filePath; }
static void Main() { Path path = new Path(); path.AddPoint(new Point3D(1, 2, 3)); path.AddPoint(new Point3D(6, -6, 1)); path.AddPoint(new Point3D(1, 2, 3)); path.AddPoint(new Point3D(5, -4, 4)); path.AddPoint(new Point3D(8, 8, 8)); path.AddPoint(new Point3D(-8, -8, -8)); path.AddPoint(new Point3D(1, 1, 3)); path.AddPoint(new Point3D(-1, 7, -3)); path.AddPoint(new Point3D(13, 5, 3)); path.AddPoint(new Point3D(-1, -12, -6)); PathStorage.SavePath(path); Path loaded = PathStorage.LoadPath("path.txt"); loaded.PrintAllSequences(); }
public static void Main() { Point3D a = new Point3D(2.26, 10.8, -5); Console.WriteLine("Point A {0}", a); Console.WriteLine("Origin {0}", Point3D.Origin); Point3D b = new Point3D(2, 8, -1); Console.WriteLine("Point B {0}", b); Console.WriteLine("The distance between A and B is {0}", Distance.CalculateDistance(a, b)); Path path = new Path(Point3D.Origin, a, b, a, b); path.AddPoint(Point3D.Origin); path.AddPoint(new Point3D(-9.99, -8, 0)); Console.WriteLine("The path is:\n{0}", path); PathStorage.SavePathToFile(@"..\..\path.txt", path); Path loadedPath = PathStorage.LoadPathFromFile(@"..\..\path.txt"); }
public static Path LoadPath() { var reader = new StreamReader(@"..\..\points.txt"); var path = new Path(); using (reader) { string currentLine = reader.ReadLine(); while (currentLine != null) { double[] coordinates = currentLine.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray(); path.AddPoint(new Point3D(coordinates[0], coordinates[1], coordinates[2])); currentLine = reader.ReadLine(); } } return(path); }
public static Path LoadPathFromFile(string fileName) { string regex = @"X: (?<x>-?\d*\.?\d+([eE][-+]?\d+)?); Y: (?<y>-?\d*\.?\d+([eE][-+]?\d+)?); Z: (?<z>-?\d*\.?\d+([eE][-+]?\d+)?)"; Path path = new Path(); StreamReader reader = new StreamReader(fileName, Encoding.UTF8); using (reader) { while (!reader.EndOfStream) { Match match = Regex.Match(reader.ReadLine(), regex); double x = double.Parse(match.Groups["x"].Value); double y = double.Parse(match.Groups["y"].Value); double z = double.Parse(match.Groups["z"].Value); Point3D point = new Point3D(x, y, z); path.AddPoint(point); } } return path; }
public static Path LoadPathFromFile(string fileName) { string regex = @"X: (?<x>-?\d*\.?\d+([eE][-+]?\d+)?); Y: (?<y>-?\d*\.?\d+([eE][-+]?\d+)?); Z: (?<z>-?\d*\.?\d+([eE][-+]?\d+)?)"; Path path = new Path(); StreamReader reader = new StreamReader(fileName, Encoding.UTF8); using (reader) { while (!reader.EndOfStream) { Match match = Regex.Match(reader.ReadLine(), regex); double x = double.Parse(match.Groups["x"].Value); double y = double.Parse(match.Groups["y"].Value); double z = double.Parse(match.Groups["z"].Value); Point3D point = new Point3D(x, y, z); path.AddPoint(point); } } return(path); }
public static Path LoadPath(string fileAddress) { Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; Path loaded = new Path(); StreamReader reader = new StreamReader(fileAddress); using (reader) { string line = reader.ReadLine(); while (line != null) { line = line.Substring(6, (line.Length - 7)); string[] coordinates = line.Split(new char[] {' ', ','}, StringSplitOptions.RemoveEmptyEntries); double x = double.Parse(coordinates[0]); double y = double.Parse(coordinates[1]); double z = double.Parse(coordinates[2]); Point3D nextPoint = new Point3D(x, y, z); loaded.AddPoint(nextPoint); line = reader.ReadLine(); } } return loaded; }
public static Path ReadPathFromFile(string fileLocation) { Path generatedPath = new Path(); StreamReader reader = new StreamReader(fileLocation); using (reader) { string currLine = reader.ReadLine(); while (currLine != null) { currLine = currLine.Substring(currLine.IndexOf("-->") + 3); int[] coordinates = currLine.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); generatedPath.AddPoint(coordinates[0], coordinates[1], coordinates[2]); currLine = reader.ReadLine(); } } return(generatedPath); }
public static Path LoadPath(string fileAddress) { Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; Path loaded = new Path(); StreamReader reader = new StreamReader(fileAddress); using (reader) { string line = reader.ReadLine(); while (line != null) { line = line.Substring(6, (line.Length - 7)); string[] coordinates = line.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); double x = double.Parse(coordinates[0]); double y = double.Parse(coordinates[1]); double z = double.Parse(coordinates[2]); Point3D nextPoint = new Point3D(x, y, z); loaded.AddPoint(nextPoint); line = reader.ReadLine(); } } return(loaded); }
static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Console.WriteLine("Creating Points"); Console.WriteLine(new string('-', 30)); var firstPoint = new Point3D(2.3, 5, 0); Console.WriteLine("First point: {0}", firstPoint); var zeroPoint = Point3D.ZeroPoint; Console.WriteLine(new string('-', 30)); Console.WriteLine("Zero point: {0}", zeroPoint); var distance = PointsDistance.CalculateDistance(firstPoint, zeroPoint); Console.WriteLine(new string('-', 30)); Console.WriteLine("Distance between the points: {0:F2} ", distance); var path = new Path(); Console.WriteLine(new string('-', 30)); Console.WriteLine("Creating path."); path.AddPoint(firstPoint); Console.WriteLine(new string('-', 30)); Console.WriteLine("Adding first point."); path.AddPoint(zeroPoint); Console.WriteLine(new string('-', 30)); Console.WriteLine("Adding zero point."); Console.WriteLine(new string('-', 30)); Console.WriteLine("Path: {0}", path.ToString()); Console.WriteLine(new string('-', 30)); Console.WriteLine("Total points in path: {0}", path.Count); path.RemovePoint(zeroPoint); Console.WriteLine(new string('-', 30)); Console.WriteLine("Removing zero point."); Console.WriteLine(new string('-', 30)); Console.WriteLine("Path: {0}", path.ToString()); Console.WriteLine(new string('-', 30)); Console.WriteLine("Total points in path: {0}", path.Count); path.Clear(); Console.WriteLine(new string('-', 30)); Console.WriteLine("Clearing path."); Console.WriteLine(new string('-', 30)); Console.WriteLine("Total points in path: {0}", path.Count); path.AddPoint(firstPoint); path.AddPoint(zeroPoint); PathStorage.SavePath(path, "input"); Console.WriteLine(new string('-', 30)); Console.WriteLine("Saving path in a text file."); PathStorage.LoadPath("input"); Console.WriteLine(new string('-', 30)); Console.WriteLine("Loading path from a text file."); }