コード例 #1
0
ファイル: PathStorage.cs プロジェクト: cwetanow/Telerik
        public static Path LoadPath(string fileName)
        {
            var reader = new StreamReader(fileName + ".txt");
            var temp = reader.ReadToEnd();
            reader.Close();
            var points = temp.Split(new char[] { '[', ']', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var newPath = new Path();
            for (int i = 0; i < points.Length - 1; i += 3)
            {
                var temporary = new Point(double.Parse(points[i]), double.Parse(points[i + 1]), double.Parse(points[i + 2]));
                newPath.Add(temporary);
            }

            return newPath;
        }
コード例 #2
0
        // reads path from file
        // file format is:
        // at first line - N, the number of points into the path
        // at each consecutive N lines - point coordinates X, Y, Z, separated by spaces
        public static Path Read(string filename)
        {
            Path result = new Path();
            using (StreamReader sr = new StreamReader(filename)) // if something goes wrong, a standard exception procedure will take place
            {
                int cnt = int.Parse(sr.ReadLine()); // reads number of points of the path
                for (int i = 0; i < cnt; i++)
                {
                    string[] coords = sr.ReadLine().Split(' '); // reads each point (X,Y,Z, separated by spaces)
                    int x = int.Parse(coords[0]);
                    int y = int.Parse(coords[1]);
                    int z = int.Parse(coords[2]);
                    result.Add(x, y, z); // and loads it into the path
                }
            }

            return result; // finally returns the path
        }
コード例 #3
0
ファイル: PathStorage.cs プロジェクト: rsmont/OOP
 public static Path LoadPath(string filePath)
 {
     Path tempPath = new Path();
     Point3d point = new Point3d();
     using (var reader = new StreamReader(filePath))
     {
         int i = 0;
         for (string line; (line = reader.ReadLine()) != null; i++)
         {
             string[] points = line.Split(',');
             point.PointX = double.Parse(points[0]);
             point.PointY = double.Parse(points[1]);
             point.PointZ = double.Parse(points[2]);
             tempPath.Add(point);
         }
     }
     return tempPath;
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: vuhoangminh/smartd
        ////////////////////////////////////////////////

        static Path MakeRandomPolygon(Random r,  int maxWidth, int maxHeight, int edgeCount, Int64 scale = 1)
        {
            Path result = new Path(edgeCount);
            for (int i = 0; i < edgeCount; i++)
            {
                result.Add(new IntPoint(r.Next(maxWidth)*scale, r.Next(maxHeight)*scale));
            }
            return result;
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: vuhoangminh/smartd
        ////////////////////////////////////////////////

        static Path IntsToPolygon(int[] ints)
        {
            int len1 = ints.Length /2;
            Path result = new Path(len1);
            for (int i = 0; i < len1; i++)
              result.Add(new IntPoint(ints[i * 2], ints[i * 2 +1]));
            return result;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: vuhoangminh/smartd
        ////////////////////////////////////////////////

        static bool LoadFromFile(string filename, Paths ppg, int dec_places, int xOffset = 0, int yOffset = 0)
        {
            double scaling;
            scaling = Math.Pow(10, dec_places);

            ppg.Clear();
            if (!File.Exists(filename)) return false;
            StreamReader sr = new StreamReader(filename);
            if (sr == null) return false;
            string line;
            if ((line = sr.ReadLine()) == null) return false;
            int polyCnt, vertCnt;
            if (!Int32.TryParse(line, out polyCnt) || polyCnt < 0) return false;
            ppg.Capacity = polyCnt;
            for (int i = 0; i < polyCnt; i++)
            {
                if ((line = sr.ReadLine()) == null) return false;
                if (!Int32.TryParse(line, out vertCnt) || vertCnt < 0) return false;
                Path pg = new Path(vertCnt);
                ppg.Add(pg);
                if (scaling > 0.999 & scaling < 1.001)
                    for (int j = 0; j < vertCnt; j++)
                    {
                        Int64 x, y;
                        if ((line = sr.ReadLine()) == null) return false;
                        char[] delimiters = new char[] { ',', ' ' };
                        string[] vals = line.Split(delimiters);
                        if (vals.Length < 2) return false;
                        if (!Int64.TryParse(vals[0], out x)) return false;
                        if (!Int64.TryParse(vals[1], out y))
                            if (vals.Length < 2 || !Int64.TryParse(vals[2], out y)) return false;
                        x = x + xOffset;
                        y = y + yOffset;
                        pg.Add(new IntPoint(x, y));
                    }
                else
                    for (int j = 0; j < vertCnt; j++)
                    {
                        double x, y;
                        if ((line = sr.ReadLine()) == null) return false;
                        char[] delimiters = new char[] { ',', ' ' };
                        string[] vals = line.Split(delimiters);
                        if (vals.Length < 2) return false;
                        if (!double.TryParse(vals[0], out x)) return false;
                        if (!double.TryParse(vals[1], out y))
                            if (vals.Length < 2 || !double.TryParse(vals[2], out y)) return false;
                        x = x * scaling + xOffset;
                        y = y * scaling + yOffset;
                        pg.Add(new IntPoint((Int64)Math.Round(x), (Int64)Math.Round(y)));
                    }
            }
            return true;
        }