Ejemplo n.º 1
0
        //型変換
        public static Poly ParsePolyFromQRCode(Procon2017MCTProtocol.SendablePolygon polygon, bool isPiece, sbyte initPieceId = -1)
        {
            int          i;
            List <Point> points = new List <Point>();
            List <Line>  lines  = new List <Line>();

            for (i = 0; i < polygon.Points.Count; i++)
            {
                points.Add(new Point(polygon.Points[i].X, polygon.Points[i].Y));
            }
            points.Add(points[0]);

            //表示する線分の設定 (ピースのみ)
            if (isPiece)
            {
                for (i = 0; i < points.Count - 1; i++)
                {
                    lines.Add(new Line(points[i], points[i + 1], initPieceId));
                }
            }

            Poly poly = new Poly(points, lines, isPiece, false);

            if (isPiece && poly.Area < 0)
            {
                poly.points.Reverse();
            }
            if (!isPiece && poly.Area > 0)
            {
                poly.points.Reverse();
            }
            return(poly);
        }
Ejemplo n.º 2
0
        public Task Append(string Data)
        {
            string QRCode = Data + ":";

            return(Task.Run(() => {
                int polygons_count;
                int itr = 0;
                for (; itr < QRCode.Length; ++itr)
                {
                    if (QRCode[itr] == ':')
                    {
                        break;
                    }
                }
                polygons_count = int.Parse(QRCode.Substring(0, itr));
                if (Polygons == null)
                {
                    Polygons = new List <Procon2017MCTProtocol.SendablePolygon>(polygons_count);
                }
                else
                {
                    Polygons.Capacity = polygons_count + Polygons.Count;
                }

                itr++;

                int itr_start = itr;
                Procon2017MCTProtocol.SendablePolygon buffer_polygon = new Procon2017MCTProtocol.SendablePolygon();
                Procon2017MCTProtocol.SendablePoint buffer_point = new Procon2017MCTProtocol.SendablePoint();
                bool IsCheckX = true;
                for (; itr < QRCode.Length && Polygons.Count < Polygons.Capacity; ++itr)
                {
                    for (; itr < QRCode.Length; ++itr)
                    {
                        if (QRCode[itr] == ' ')
                        {
                            buffer_polygon = new Procon2017MCTProtocol.SendablePolygon(int.Parse(QRCode.Substring(itr_start, itr - itr_start)));
                            break;
                        }
                    }
                    itr_start = itr + 1;
                    ++itr;
                    for (; itr < QRCode.Length; ++itr)
                    {
                        if (QRCode[itr] == ' ')
                        {
                            if (IsCheckX)
                            {
                                buffer_point.X = int.Parse(QRCode.Substring(itr_start, itr - itr_start));
                            }
                            else
                            {
                                buffer_point.Y = int.Parse(QRCode.Substring(itr_start, itr - itr_start));
                                buffer_polygon.Points.Add(buffer_point);
                            }
                            IsCheckX = !IsCheckX;
                            itr_start = itr + 1;
                        }
                        else if (QRCode[itr] == ':')
                        {
                            if (IsCheckX)
                            {
                                throw new FormatException();
                            }
                            buffer_point.Y = int.Parse(QRCode.Substring(itr_start, itr - itr_start));
                            buffer_polygon.Points.Add(buffer_point);
                            itr++;
                            itr_start = itr;
                            IsCheckX = true;
                            break;
                        }
                    }
                    Polygons.Add(buffer_polygon);
                }

                if (Frames == null)
                {
                    Frames = new List <Procon2017MCTProtocol.SendablePolygon>();
                }
                for (; itr < QRCode.Length; ++itr)
                {
                    for (; itr < QRCode.Length; ++itr)
                    {
                        if (QRCode[itr] == ' ')
                        {
                            buffer_polygon = new Procon2017MCTProtocol.SendablePolygon(int.Parse(QRCode.Substring(itr_start, itr - itr_start)));
                            break;
                        }
                    }
                    itr_start = itr + 1;
                    ++itr;
                    for (; itr < QRCode.Length; ++itr)
                    {
                        if (QRCode[itr] == ' ')
                        {
                            if (IsCheckX)
                            {
                                buffer_point.X = int.Parse(QRCode.Substring(itr_start, itr - itr_start));
                            }
                            else
                            {
                                buffer_point.Y = int.Parse(QRCode.Substring(itr_start, itr - itr_start));
                                buffer_polygon.Points.Add(buffer_point);
                            }
                            IsCheckX = !IsCheckX;
                            itr_start = itr + 1;
                        }
                        else if (QRCode[itr] == ':')
                        {
                            if (IsCheckX)
                            {
                                throw new FormatException();
                            }
                            buffer_point.Y = int.Parse(QRCode.Substring(itr_start, itr - itr_start));
                            buffer_polygon.Points.Add(buffer_point);
                            itr++;
                            itr_start = itr;
                            IsCheckX = true;
                            break;
                        }
                    }
                    Frames.Add(buffer_polygon);
                }
            }));
        }