Exemplo n.º 1
0
        private static void PlayWithPaths()
        {
            Point3D point = new Point3D(1, 2, 3);

            Console.WriteLine(point);
            Point3D point1 = new Point3D(1, 2, 3);
            Point3D point2 = new Point3D(1, 2, 3);
            Point3D point3 = new Point3D(1, 2, 3);
            Path    path   = new Path(new List <Point3D>()
            {
                point1, point2, point3
            });

            Path LoadedPath = PathStorage.LoadPath(@"C:\Users\LUCHI\Documents\Mosh\part 2");

            foreach (Point3D LoadPoint in LoadedPath.Points)
            {
                Console.WriteLine();
            }
        }
Exemplo n.º 2
0
        // Load method
        // The paths are loaded from the loads.txt file and are put into the pathStorage field
        public static void LoadPaths()
        {
            StreamReader reader = new StreamReader("loads.txt", Encoding.GetEncoding("UTF-8"));
            string       allSaves;

            // Read the file and put the information into the string allSaves
            using (reader)
            {
                allSaves = reader.ReadToEnd();
            }

            // Split the string and get all the paths
            string[] paths = allSaves.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

            for (int path = 0; path < paths.Length; path++)
            {
                // (1, 2, 3) -> (4, 5, 6) => [1, 2, 3, 4, 5, 6]
                string[] pointsCoordinates = paths[path].Split(new string[] { "(", ")", " ", "->", "," }, StringSplitOptions.RemoveEmptyEntries);

                Path pathToBeAddedInPathStorage = new Path();

                // The next loop generates the path points
                // From [1, 2, 3, 4, 5, 6] => (1, 2, 3). We add that point to the pathToBeAddedInPathStorage.
                // Then we get point (4, 5, 6) and we add that point to the pathToBeAddedInPathStorage
                for (int i = 0; i < pointsCoordinates.Length; i += 3)
                {
                    Point3D point = new Point3D(double.Parse(pointsCoordinates[i]),
                                                double.Parse(pointsCoordinates[i + 1]),
                                                double.Parse(pointsCoordinates[i + 2]));

                    pathToBeAddedInPathStorage.AddPoint3D(point);
                }

                // Add the current loaded path into the pathStorage
                PathStorage.AddPath(pathToBeAddedInPathStorage);
            }
        }
Exemplo n.º 3
0
        static void Main()
        {
            // Printing the starting point
            Console.WriteLine("The start point is with coordinates: {0}", Point3D.StartPoint);
            // Adding and printing points
            Point3D firstPoint = new Point3D(3, 4.4, 5);

            Console.WriteLine("Coordinates of the first point: " + firstPoint.ToString());
            Point3D secondPoint = new Point3D(1, 2, 3);

            Console.WriteLine("Coordinates of the second point: " + secondPoint.ToString());
            // Printing the distance between the two points
            double distance = CalculateDistance.DistanceBetweenPoints(firstPoint, secondPoint);

            Console.WriteLine("The distance between the two points is: {0:F2}", distance);
            // Making a path and adding points in it
            Path firstPath = new Path();

            firstPath.AddPoint(3, 4, 5);
            firstPath.AddPoint(6, 7, 8);
            // Saving and loading the path. You can see it in the file "FirstPath.exe" in the folder of the project
            PathStorage.SavePath(firstPath, "FirstPath");
            PathStorage.SavePath(PathStorage.LoadPath("FirstPath"), "ResultAfterLoadingTheFirstPath");
        }
Exemplo n.º 4
0
        static void Main()
        {
            // first create 3 points
            Point3D p1 = new Point3D(1.3, 2.3, 3.1);
            Point3D p2 = new Point3D(4.2, 2.8, -5);
            Point3D p3 = new Point3D(1.1, 2.5, 11.7);

            // calculate distance between first two points
            Console.WriteLine("Distance between p1 and p2: {0}", CalculateDistance.TwoPoints(p1, p2));

            // create two test paths and save them to two files
            Path testPath1 = new Path();

            testPath1.AddPoint(p1);
            testPath1.AddPoint(p2);
            testPath1.AddPoint(p3);
            PathStorage.SavePath(testPath1, "SavedTestPath1");

            Path testPath2 = new Path();

            testPath2.AddPoint(p3);
            testPath2.AddPoint(p2);
            testPath2.AddPoint(p1);
            PathStorage.SavePath(testPath2, "SavedTestPath2");

            // create third path and load its points from file of first path
            Path testPath3 = new Path();

            testPath3 = PathStorage.LoadPath("SavedTestPath1");

            // save third path to SavedTestPath3.txt
            PathStorage.SavePath(testPath3, "SavedTestPath3");

            // SavedTestPath3.txt should be the same as SavedTestPath1.txt

            try
            {
                testPath3 = PathStorage.LoadPath("NonExistentFile");
            }
            catch (Exception ex)
            {
                Console.WriteLine("An expected error occurred. Error message:\n{0}", ex.Message);
            }

            //Point3D firstPoint = new Point3D(3, 4.4, 5);
            //Point3D secondPoint = new Point3D(1, 2, 3);
            //Console.WriteLine(firstPoint.ToString());
            //Console.WriteLine(secondPoint.ToString());
            //double result = CalculateDistance.TwoPoints(firstPoint, secondPoint);
            //Console.WriteLine("{0:F2}",result);
            //Path myPath = new Path();
            //myPath.AddPoint(4.5, 4, 50.8);
            //myPath.AddPoint(5, 2, 5);
            //PathStorage.SavePath(myPath, "Path1");

            //Path mySecondPath = new Path();
            //mySecondPath.AddPoint(55, 5, 555);
            //mySecondPath.AddPoint(5, 5, 5);
            //mySecondPath.AddPoint(1, 4, 6);
            //PathStorage.SavePath(mySecondPath, "Path2");
            //PathStorage.SavePath(PathStorage.LoadPath("Path2"), "againPath2");
        }
Exemplo n.º 5
0
 // To test it delete the saves.txt file in the Debug folder of the assembly.
 // Then write down some paths in the loads.txt file. Each path is on a single line.
 // The format of the paths is shown in the loads.txt file.
 public static void TestMethod()
 {
     PathStorage.LoadPaths(); // Loads the paths from the loads.txt file
     PathStorage.SavePaths(); // Saves the paths into the saves.txt file
 }