コード例 #1
0
        static public int parse_lion(VertexStorage path, Color[] colors, int[] path_idx)
        {
            // Parse the lion and then detect its bounding
            // box and arrange polygons orientations (make all polygons
            // oriented clockwise or counterclockwise)

            int npaths = 0;

            string[] splitOnNL = g_lion.Split('\n');
            foreach (string LineString in splitOnNL)
            {
                int c;
                if (LineString.Length > 0 &&
                    LineString[0] != 'M' &&
                    Int32.TryParse(LineString, NumberStyles.HexNumber, null, out c))
                {
                    // New color. Every new color creates new path in the path object.
                    path.ClosePolygon();
                    colors[npaths]   = Color.rgb8_packed((int)c);
                    path_idx[npaths] = path.start_new_path();
                    npaths++;
                }
                else
                {
                    bool     startedPoly  = false;
                    string[] splitOnSpace = LineString.Split(' ');
                    for (int i = 0; i < splitOnSpace.Length; i++)
                    {
                        string[] splitOnComma = splitOnSpace[i].Split(',');
                        if (splitOnComma.Length > 1)
                        {
                            double x = 0.0;
                            double y = 0.0;
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);

                            if (!startedPoly)
                            {
                                startedPoly = true;
                                path.ClosePolygon();
                                path.MoveTo(x, y);
                            }
                            else
                            {
                                path.LineTo(x, y);
                            }
                        }
                    }
                }
            }

            path.arrange_orientations_all_paths(ShapePath.FlagsAndCommand.FlagCW);
            return(npaths);
        }
コード例 #2
0
        static public List <ColoredVertexStorage> parse_lion()
        {
            // Parse the lion and then detect its bounding
            // box and arrange polygons orientations (make all polygons
            // oriented clockwise or counterclockwise)

            var paths = new List <ColoredVertexStorage>();

            ColoredVertexStorage currentPath = null;

            string[] splitOnNL = g_lion.Split('\n');
            foreach (string LineString in splitOnNL)
            {
                int c;
                if (LineString.Length > 0 &&
                    LineString[0] != 'M' &&
                    Int32.TryParse(LineString, NumberStyles.HexNumber, null, out c))
                {
                    // New color. Every new color creates new path in the path object.

                    if (currentPath != null)
                    {
                        currentPath.VertexStorage.ClosePolygon();
                        currentPath.VertexStorage.arrange_orientations_all_paths(ShapePath.FlagsAndCommand.FlagCW);
                    }

                    currentPath = new ColoredVertexStorage()
                    {
                        Color         = Color.rgb8_packed((int)c),
                        VertexStorage = new VertexStorage()
                    };

                    currentPath.VertexStorage.start_new_path();

                    paths.Add(currentPath);
                }
                else
                {
                    bool     startedPoly  = false;
                    string[] splitOnSpace = LineString.Split(' ');
                    for (int i = 0; i < splitOnSpace.Length; i++)
                    {
                        string[] splitOnComma = splitOnSpace[i].Split(',');
                        if (splitOnComma.Length > 1)
                        {
                            double x = 0.0;
                            double y = 0.0;
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);

                            if (!startedPoly)
                            {
                                startedPoly = true;
                                currentPath.VertexStorage.MoveTo(x, y);
                            }
                            else
                            {
                                currentPath.VertexStorage.LineTo(x, y);
                            }
                        }
                    }
                }
            }

            currentPath.VertexStorage.ClosePolygon();
            currentPath.VertexStorage.arrange_orientations_all_paths(ShapePath.FlagsAndCommand.FlagCW);

            return(paths);
        }