示例#1
0
        // path should contain only polylines ( use Flatten )
        // furthermore the constructor assumes that all Subpathes of path except the first one are holes
        public Polygon(GraphicsPath path)
        {
            byte[] pathTypes = path.PathTypes;

            NofContours = 0;
            foreach (byte b in pathTypes)
            {
                if ((b & ((byte)PathPointType.CloseSubpath)) != 0)
                {
                    NofContours++;
                }
            }

            ContourIsHole = new bool[NofContours];
            Contour       = new VertexList[NofContours];

            for (int i = 0; i < NofContours; i++)
            {
                ContourIsHole[i] = (i == 0);
            }

            int contourNr = 0;

            List <PointF> contour = new List <PointF>();

            PointF[] pathPoints = path.PathPoints;

            for (int i = 0; i < pathPoints.Length; i++)
            {
                contour.Add(pathPoints[i]);

                if ((pathTypes[i] & ((byte)PathPointType.CloseSubpath)) != 0)
                {
                    PointF[]   pointArray = contour.ToArray();
                    VertexList vl         = new VertexList(pointArray);
                    Contour[contourNr++] = vl;
                    contour.Clear();
                }
            }
        }
示例#2
0
        // path should contain only polylines ( use Flatten )
        // furthermore the constructor assumes that all Subpathes of path except the first one are holes
        public Polygon(GraphicsPath path)
        {
            byte[] pathTypes = path.PathTypes;

            NofContours = 0;
            foreach (byte b in pathTypes)
            {
                if ((b & ((byte)PathPointType.CloseSubpath)) != 0)
                {
                    NofContours++;
                }
            }

            ContourIsHole = new bool[NofContours];
            Contour = new VertexList[NofContours];

            for (int i = 0; i < NofContours; i++)
            {
                ContourIsHole[i] = (i == 0);
            }

            int contourNr = 0;

            List<PointF> contour = new List<PointF>();

            PointF[] pathPoints = path.PathPoints;

            for (int i = 0; i < pathPoints.Length; i++)
            {
                contour.Add(pathPoints[i]);

                if ((pathTypes[i] & ((byte)PathPointType.CloseSubpath)) != 0)
                {
                    PointF[] pointArray = contour.ToArray();
                    VertexList vl = new VertexList(pointArray);
                    Contour[contourNr++] = vl;
                    contour.Clear();
                }
            }
        }