Exemple #1
0
 private void getReadAndDraw(string file)
 {
     if (file != "not possible")
     {
         lastPosition = DataDownloader.readPosition(file);
     }
     else
     {
         System.Media.SystemSounds.Beep.Play();
     }
     lastPoints = calculatePoints(lastPosition);
     pictureBox1.Refresh();
 }
Exemple #2
0
        public static SingleRead readPosition(string fileName)
        {
            string localFilepath = "..\\..\\cache";

            if (!Directory.Exists(localFilepath))
            {
                Directory.CreateDirectory(localFilepath);
            }
            string path = Path.Combine(new string[] { localFilepath, fileName });

            if (!File.Exists(path))
            {
                string fullUrl         = url + fileName;
                byte[] fileByteContent = ReadFileFromUrl(fullUrl);
                File.WriteAllBytes(path, fileByteContent);
            }
            string[] fileLines = File.ReadAllLines(path);

            var result = new SingleRead();

            string[] xytmp = fileLines[1].Split(new char[] { ' ' });
            result.x = Convert.ToInt32(xytmp[0]);
            result.y = Convert.ToInt32(xytmp[1]);

            var distTmp = new List <double>();

            for (int i = 0; i < 36; i++)
            {
                if (fileLines[i + 2] != "inf")
                {
                    distTmp.Add(Convert.ToDouble(fileLines[i + 2].Replace('.', ',')));
                }
                else
                {
                    distTmp.Add(-1);
                }
            }
            result.distance   = distTmp.ToArray();
            result.MOVE_EAST  = fileLines[38].Replace("MOVE_EAST: ", "");
            result.MOVE_WEST  = fileLines[39].Replace("MOVE_WEST: ", "");;
            result.MOVE_SOUTH = fileLines[40].Replace("MOVE_SOUTH: ", "");;
            result.MOVE_NORTH = fileLines[41].Replace("MOVE_NORTH: ", "");;

            return(result);
        }
Exemple #3
0
        private PointF[] calculatePoints(SingleRead position)
        {
            int   shift = 0;
            float zoom  = 1F;

            scanFrom = new PointF(shift + position.x * zoom, shift + position.y * zoom);
            var   points = new List <PointF>();
            float x, y;

            for (int i = 0; i < position.distance.Length; i++)
            {
                if (position.distance[i] >= 0)
                {
                    x = position.x * zoom + (float)(position.distance[i] * Math.Sin(i * Math.PI / 18.0) * zoom);
                    y = position.y * zoom - (float)(position.distance[i] * Math.Cos(i * Math.PI / 18.0) * zoom);
                    points.Add(new PointF(shift + x, shift + y));
                }
            }

            return(points.ToArray());
        }