Exemplo n.º 1
0
        public void Parse()
        {
            int     polychains = int.Parse(NextToken());
            BoundsF bounds     = new BoundsF();

            VertCount = 0;

            for (int i = 0; i < polychains; ++i)
            {
                var chain = new PolyChain();

                int verts = int.Parse(NextToken());
                VertCount += verts;
                chain.In   = (NextToken() == "in");

                for (int x = 0; x < verts; ++x)
                {
                    var vert = new PointF(float.Parse(NextToken()), float.Parse(NextToken()));
                    chain.Vertices.Add(vert);

                    bounds.Merge(vert);
                }

                for (int x = 0; x < verts; ++x)
                {
                    var vert = chain.Vertices[x];
                    vert.X -= bounds.Mins.X;
                    vert.Y -= bounds.Mins.Y;

                    vert.X /= bounds.Maxs.X - bounds.Mins.X;
                    vert.Y /= bounds.Maxs.Y - bounds.Mins.X;

                    if (vert.X < 0 || vert.Y < 0 || vert.X > 1 || vert.X > 1)
                    {
                        throw new Exception();
                    }
                    chain.Vertices[x] = vert;
                    chain.Connections.Add(int.Parse(NextToken()));
                }

                PolyChains.Add(chain);
            }
        }
Exemplo n.º 2
0
        public void Parse()
        {
            int polychains = int.Parse(NextToken());
            BoundsF bounds = new BoundsF();
            VertCount = 0;

            for (int i = 0; i < polychains; ++i)
            {
                var chain = new PolyChain();

                int verts = int.Parse(NextToken());
                VertCount += verts;
                chain.In = (NextToken() == "in");

                for (int x = 0; x < verts; ++x)
                {
                    var vert = new PointF(float.Parse(NextToken()), float.Parse(NextToken()));
                    chain.Vertices.Add(vert);

                    bounds.Merge(vert);
                }

                for (int x = 0; x < verts; ++x)
                {
                    var vert = chain.Vertices[x];
                    vert.X -= bounds.Mins.X;
                    vert.Y -= bounds.Mins.Y;

                    vert.X /= bounds.Maxs.X - bounds.Mins.X;
                    vert.Y /= bounds.Maxs.Y - bounds.Mins.X;

                    if (vert.X < 0 || vert.Y < 0 || vert.X > 1 || vert.X > 1)
                        throw new Exception();
                    chain.Vertices[x] = vert;
                    chain.Connections.Add(int.Parse(NextToken()));
                }

                PolyChains.Add(chain);
            }
        }