static void Main(string[] args)
        {
            // Origin Point
            Console.WriteLine(Point3D.Origin);
            Console.WriteLine();

            // Distance Between Two Points
            Point3D p1 = new Point3D(0, 2, 3);
            Point3D p2 = new Point3D(1, 4, 3);
            Console.WriteLine(p1);
            Console.WriteLine(p2);
            Console.WriteLine("Distance: {0}", Point.Distance(p1, p2));
            Console.WriteLine();

            // Save and Load Paths
            Path path1 = new Path();
            path1.AddPoint(3, 4, 5);
            path1.AddPoint(1, 1, 1);
            PathStorage.SavePath(path1, false);

            Path path2 = new Path();
            path2.AddPoint(6, 8, 6);
            path2.AddPoint(1, 2, 3);
            PathStorage.SavePath(path2, true);

            Console.WriteLine(PathStorage.LoadPath());
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //Problem 1 - Point3D
            
            Point3D p1 = new Point3D(1, 2, 3);
            Point3D p2 = new Point3D(5.35, 2.7, -3.29);
            Console.WriteLine();

            Console.WriteLine(p1);
            Console.WriteLine(p2);
            Console.WriteLine(Point3D.StartingPoint);
            Console.WriteLine();
            Console.WriteLine(new String('*', 20));
            Console.WriteLine();
            
            //Problem 2 - Distance Calculator

            double distance = DistanceCalculator.distance(p1, p2);
            Console.WriteLine(distance);
            Console.WriteLine();
            Console.WriteLine(new String('*', 20));
            Console.WriteLine();

            //Problem 3 - Paths

            Path path = new Path(p1, p2, Point3D.StartingPoint);
            Console.WriteLine("Save points {0} in path.", path);
            Storage.SaveFile("paths.txt", path);
            Path loadFile = Storage.LoadPath("paths.txt");
            Console.WriteLine("Load path: {0}", loadFile);
        }
        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}", CalcDistance.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);
            }
        }
        static void Main()
        {
            // test point3D
            Point3D point = new Point3D(5.5, 2.1, 100);
            Console.WriteLine("Point3D test:");
            Console.WriteLine(point);
            Console.WriteLine();

            // test zero point
            Console.WriteLine("Zero point test:");
            Console.WriteLine(Point3D.ZeroPoint);
            Console.WriteLine();

            //test calculate the distance
            Console.WriteLine("Calculate distance tests:");
            Point3D point1 = new Point3D(-7, -4, 3);
            Console.WriteLine("Point1: {0}", point1);
            Point3D point2 = new Point3D(17, 6, 2.5);
            Console.WriteLine("Point2: {0}", point2);
            double distance = Space3D.CalculateDistance(point1, point2);
            Console.WriteLine("Distance between {0}, {1} = {2}", point1, point2, distance);
            Console.WriteLine();
            Point3D point3 = new Point3D(1, 1, 1);
            distance = Space3D.CalculateDistance(Point3D.ZeroPoint, point3);
            Console.WriteLine("Distance between zero point and point {0} = {1}", point3, distance);
            Console.WriteLine();

            // test path
            Console.WriteLine("Test path:");
            point = new Point3D(1, 2, 3);
            Path path = new Path(point);
            Console.WriteLine("Path is created with statrt point {0}", point);
            point = new Point3D(4, 5, 6);
            path.AddPoint(point);
            Console.WriteLine("Point {0} is added to the path", point);
            Point3D[] points = new Point3D[2];
            points[0] = new Point3D(10, 20, 30);
            points[1] = new Point3D(0.1, 200, 300.5);
            Console.WriteLine("Points {0} and {1} are added to the path", points[0], points[1]);
            path.AddPoints(points);
            Console.WriteLine("Path: ");
            Console.WriteLine(path);
            Console.WriteLine();

            List<Point3D> test = path.Points;
            point = new Point3D(100, 200, 300);
            test[0] = point;
            Console.WriteLine("Path: ");
            Console.WriteLine(path);
            Console.WriteLine();

            // test  PathStorage
            Console.WriteLine("Test PathStorage:");
            string filePath = @"..\..\PathStorageTest.txt";
            PathStorage.SavePath(path, filePath);
            Console.WriteLine("The path is stored to file {0}", filePath);
            Path pathReaded = PathStorage.LoadPath(filePath);
            Console.WriteLine("The path is readed from file {0}", filePath);
            Console.WriteLine("Path readed from file: ");
            Console.WriteLine(pathReaded);
            path.Clear();
            // test clear path
            Console.WriteLine("The first created path is cleared");
            Console.WriteLine(path);
        }