Exemplo n.º 1
0
        public static List<Point3D> Load(StreamReader reader)
        {
            List<Point3D> list = new List<Point3D>();

            using (reader)
            {
                string line = reader.ReadLine();

                while (line != null)
                {
                    var coordinates = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    var point = new Point3D(int.Parse(coordinates[0]), int.Parse(coordinates[1]), int.Parse(coordinates[2]));

                    list.Add(point);

                    line = reader.ReadLine();
                }
            }

            return list;
        }
Exemplo n.º 2
0
        public static void Main()
        {
            // Create instances of 2 points
            Point3D point1 = new Point3D(1, 2, 3);
            Point3D point2 = new Point3D(1, 3, 2);

            // Testing ToString() override
            Console.WriteLine("{0}  -->  ToString() test" , Point3D.PointO.ToString());
            Console.WriteLine("{0}  -->  ToString() test", point1.ToString());
            AddSeparator();

            // Calculate Distance Test
            Console.WriteLine("{0:F2}  -->  Calculate Distance test",Point3D.CalculateDistance(point1, point2));
            AddSeparator();

            // Load points test
            Console.WriteLine("PathStorage Load Method Test");
            Console.WriteLine();
            StreamReader reader = new StreamReader("../../PointsLoad.txt");

            var points = PathStorage.Load(reader);

            for (int i = 0; i < points.Count; i++)
            {
                Console.WriteLine(points[i].ToString());
            }

            AddSeparator();

            // Save points test
            Console.WriteLine("PathStorage Save Method Test");
            Console.WriteLine();
            var writer = new StreamWriter("../../PointsSave.txt");
            PathStorage.Save(writer, points);
            Console.WriteLine("Save done!");
            AddSeparator();
        }
        /*
            Problem 3. Static class

            Write a static class with a static method to calculate the distance between two points in the 3D space.
         */
        public static double Distance(Point3D point1, Point3D point2)
        {
            double distance = 0;
            distance = Math.Sqrt((point2.X - point1.X) * (point2.X - point1.X) + (point2.Y - point1.Y) * (point2.Y - point1.Y) + (point2.Z - point1.Z) * (point2.Z - point1.Z));
            return distance;
        }