// path should contain only polylines ( use Flatten ) // furthermore the constructor assumes that all Subpathes of path except the first one are holes public GpcPolygon(GraphicsPath path) { NofContours = 0; foreach (byte b in path.PathTypes) { if ((b & ((byte)PathPointType.CloseSubpath)) != 0) NofContours++; } ContourIsHole = new bool[NofContours]; Contour = new GpcVertexList[NofContours]; for (int i = 0; i < NofContours; i++) ContourIsHole[i] = (i == 0); int contourNr = 0; ArrayList contour = new ArrayList(); for (int i = 0; i < path.PathPoints.Length; i++) { contour.Add(path.PathPoints[i]); if ((path.PathTypes[i] & ((byte)PathPointType.CloseSubpath)) != 0) { PointF[] pointArray = (PointF[])contour.ToArray(typeof(PointF)); GpcVertexList vl = new GpcVertexList(pointArray); Contour[contourNr++] = vl; contour.Clear(); } } }
public void AddContour(GpcVertexList contour, bool contourIsHole) { bool[] hole = new bool[NofContours + 1]; GpcVertexList[] cont = new GpcVertexList[NofContours + 1]; for (int i = 0; i < NofContours; i++) { hole[i] = ContourIsHole[i]; cont[i] = Contour[i]; } hole[NofContours] = contourIsHole; cont[NofContours++] = contour; ContourIsHole = hole; Contour = cont; }