System.Drawing.Drawing2D.ExtendedGeneralPath.GetPathData C# (CSharp) Method

GetPathData() private method

private GetPathData ( ) : System.Drawing.Drawing2D.PathData
return System.Drawing.Drawing2D.PathData
		private PathData GetPathData ()
		{
			PathData pathData = new PathData();
			int nPts = PointCount;
			for (int i = 0; i < TypesCount; i++)
				if ((Types [i] & SEG_MASK) == SEG_QUADTO)
					nPts++;

			pathData.Types = new byte [nPts];
			pathData.Points = new PointF [nPts];
			int tpos = 0;
			int ppos = 0;
			int cpos = 0;
			byte marker;
			bool start;
			for (int i = 0; i < TypesCount; i++) {
				sbyte segmentType = (sbyte)(Types [i] & SEG_MASK);

				// set the masks and the markers
				marker = ((Types [i] & SEG_MARKER) != 0) ? (byte)PathPointType.PathMarker : (byte)0;
				start = ((Types [i] & SEG_START) != 0);
				
				switch (segmentType) {
					case SEG_CLOSE:
						pathData.Types [tpos - 1] = (byte) (pathData.Types [tpos - 1] | (byte) PathPointType.CloseSubpath | marker);
						break;
					case SEG_MOVETO:
						pathData.Types [tpos++] = (byte)((byte) PathPointType.Start | marker);
						pathData.Points [ppos++] = new PointF (Coords [cpos++], Coords [cpos++]);
						break;
					case SEG_LINETO:
						pathData.Types [tpos++] = (byte) ((byte) PathPointType.Line | marker);
						pathData.Points [ppos++] = new PointF (Coords [cpos++], Coords [cpos++]);
						break;
					case SEG_QUADTO:
						/*
							.net does not support Quadratic curves, so convert to Cubic according to http://pfaedit.sourceforge.net/bezier.html
							  
							The end points of the cubic will be the same as the quadratic's.
							CP0 = QP0
							CP3 = QP2 

							The two control points for the cubic are:

							CP1 = QP0 + 2/3 *(QP1-QP0)
							CP2 = CP1 + 1/3 *(QP2-QP0) 
						*/

						float x0 = Coords[cpos-2]; //QP0
						float y0 = Coords[cpos-1]; //QP0
			
						float x1 = x0 + (2/3 * (Coords [cpos++]-x0));
						float y1 = y0 + (2/3 * (Coords [cpos++]-y0));

						float x3 = Coords [cpos++]; //QP2
						float y3 = Coords [cpos++]; //QP2
						
						float x2 = x1 + (1/3 * (x3-x0));
						float y2 = y1 + (1/3 * (y3-y0));

						pathData.Types [tpos++] = (byte)(byte) PathPointType.Bezier;
						pathData.Points [ppos++] = new PointF (x1, y1);
						pathData.Types [tpos++] = (byte)(byte) PathPointType.Bezier;
						pathData.Points [ppos++] = new PointF (x2, y2);
						pathData.Types [tpos++] = (byte) ((byte)PathPointType.Bezier | marker);
						pathData.Points [ppos++] = new PointF (x3, y3);
						break;
					case SEG_CUBICTO:
						pathData.Types [tpos++] = (byte)(byte) PathPointType.Bezier3;
						pathData.Points [ppos++] = new PointF (Coords [cpos++], Coords [cpos++]);
						pathData.Types [tpos++] = (byte) PathPointType.Bezier3;
						pathData.Points [ppos++] = new PointF (Coords [cpos++], Coords [cpos++]);
						pathData.Types [tpos++] = (byte) ((byte)PathPointType.Bezier3 | marker);
						pathData.Points [ppos++] = new PointF (Coords [cpos++], Coords [cpos++]);
						break;
				}
			}
			return pathData;
		}