예제 #1
0
        public static List <Path3D> LoadPaths(string fullFilename)
        {
            try
            {
                List <Path3D> paths = new List <Path3D>();
                using (StreamReader sr = new StreamReader(fullFilename, Encoding.GetEncoding("UTF-8")))
                {
                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        Path3D points = new Path3D();
                        var    lines  = line.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var l in lines)
                        {
                            points.Add(Point3D.Deserialize(l));
                        }

                        line = sr.ReadLine();
                        paths.Add(points);
                    }
                }
                return(paths);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex.InnerException;
            }
        }
예제 #2
0
        // Save and load paths in 3D space from a text file
        public static void Main()
        {
            // Create 3 points in space
            Point3D p1 = new Point3D(2, 3, 4);
            Point3D p2 = new Point3D(5, 6, 7);
            Point3D p3 = new Point3D(8, 9, 0);

            // Create a path from the points
            Path3D pathSave = new Path3D(p1, p2, p3);

            // Print the path
            Console.WriteLine(@"Path in 3D space to save to file (...\...\path.txt):");
            pathSave.PrintPath();

            // Save the path to a file
            string file = @"...\...\path.txt";
            Path3dStorage.SavePathToFile(pathSave, file);

            // Load the path from the file
            Path3D pathLoad = Path3dStorage.LoadPathFromFile(file);

            // Print the loaded path
            Console.WriteLine();
            Console.WriteLine(@"Path in 3D space loaded from file (...\...\path.txt):");
            pathLoad.PrintPath();

            // Calculate the distance between two points in the 3D space.
            double p1p2 = Distance3D.CalcDistance(p1, p2);
            Console.WriteLine("\nDistance between p{0} and p{1}: {2:F2}", p1, p2, p1p2);
        }
예제 #3
0
파일: Storage.cs 프로젝트: ttitto/CSharp
        public static List<Path3D> LoadPaths(string fullFilename)
        {
            try
            {
                List<Path3D> paths = new List<Path3D>();
                using (StreamReader sr = new StreamReader(fullFilename, Encoding.GetEncoding("UTF-8")))
                {

                    string line = sr.ReadLine();
                    while (line != null)
                    {
                        Path3D points = new Path3D();
                        var lines = line.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var l in lines)
                        {
                            points.Add(Point3D.DeSerialize(l));
                        }

                        line = sr.ReadLine();
                        paths.Add(points);
                    }
                }
                return paths;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex.InnerException;
            }



        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine(Point3D.StartingPoint.ToString());

            Point3D rectA = new Point3D("A", 1.2, 3, 5.6);
            Point3D rectB = new Point3D("B", -1.2, 3, 5.6);
            Point3D rectC = new Point3D("C", 1.2, -3, 5.6);
            Point3D rectD = new Point3D("D", 1.2, 3, -5.6);

            Path3D path = new Path3D(rectA, rectB, rectC, rectD);
            Console.WriteLine(path.ToString());

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

            Console.WriteLine(DistanceCalculator.CalculateDistance3D(rectA, rectD));

            //Storage tests
            Storage.SavePath(@"../../user_files/SavedPaths.txt",false, path);
            Storage.SavePath(@"../../user_files/SavedPaths.txt", true, path);

         var loadedList=   Storage.LoadPaths(@"../../user_files/SavedPaths.txt");
         loadedList.ForEach(p=>Console.WriteLine(p.ToString()));

        }
예제 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine(Point3D.StartingPoint.ToString());

            Point3D rectA = new Point3D("A", 1.2, 3, 5.6);
            Point3D rectB = new Point3D("B", -1.2, 3, 5.6);
            Point3D rectC = new Point3D("C", 1.2, -3, 5.6);
            Point3D rectD = new Point3D("D", 1.2, 3, -5.6);

            Path3D path = new Path3D(rectA, rectB, rectC, rectD);

            Console.WriteLine(path.ToString());

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

            Console.WriteLine(DistanceCalculator.CalculateDistance3D(rectA, rectD));

            //Storage tests
            Storage.SavePath(@"../../user_files/SavedPaths.txt", false, path);
            Storage.SavePath(@"../../user_files/SavedPaths.txt", true, path);

            var loadedList = Storage.LoadPaths(@"../../user_files/SavedPaths.txt");

            loadedList.ForEach(p => Console.WriteLine(p.ToString()));
        }
예제 #6
0
 public static void SavePathToFile(Path3D path3D, string file)
 {
     using (StreamWriter writer = new StreamWriter(file))
     {
         foreach (var point in path3D)
         {
             writer.WriteLine(point);
         }
     }
 }
예제 #7
0
        /// <summary>
        /// Reads a list of lines which contain points in 3D space and adds them to a path.
        /// </summary>
        /// <param name="fileLines">The list of lines.</param>
        /// <returns>Returns the path as a list of points.</returns>
        private static Path3D ParsePath(List<string> fileLines)
        {
            Path3D path = new Path3D();

            // string.Format("({0}, {1}, {2})", this.X, this.Y, this.Z);
            foreach (var line in fileLines)
            {
                double[] coord = line.Split(Separators, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
                Point3D pt = new Point3D(coord[0], coord[1], coord[2]);
                path.AddPoint(pt);
            }

            return path;
        }
예제 #8
0
 public static void SavePath(string fullFilename, bool append, Path3D path)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(fullFilename, append, Encoding.GetEncoding("UTF-8")))
         {
             sw.WriteLine(path.ToString());
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw ex.InnerException;
     }
 }
예제 #9
0
파일: Storage.cs 프로젝트: ttitto/CSharp
 public static void SavePath(string fullFilename, bool append, Path3D path)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(fullFilename, append, Encoding.GetEncoding("UTF-8")))
         {
             sw.WriteLine(path.ToString());
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw ex.InnerException;
     }
 }
예제 #10
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            Console.WriteLine(Point3D.StartingPoint.ToString());

            Point3D rectA = new Point3D("A", 1.4, 3, 35.6);
            Point3D rectB = new Point3D("B", 3.2, 5, 15.6);

            Console.WriteLine(rectB.ToString());
            Point3D rectC = new Point3D("C", 1.2, -3, 2.6);
            Point3D rectD = new Point3D("D", 2.2, 4, -5.6);

            Path3D path = new Path3D(rectA, rectB, rectC, rectD);

            Console.WriteLine("Distance between rectA and rectD : {0}", DistanceCalculator.CalculateDistance3D(rectA, rectD));

            Storage.SavePath(@"../../UserFiles/SavedPaths.txt", false, path);
            Storage.SavePath(@"../../UserFiles/SavedPaths.txt", true, path);

            var loadedList = Storage.LoadPaths(@"../../UserFiles/SavedPaths.txt");

            loadedList.ForEach(p => Console.WriteLine(p.ToString()));
        }