System.Drawing.Graphics.make_arc C# (CSharp) Method

make_arc() static private method

static private make_arc ( CGContext graphics, bool start, float x, float y, float width, float height, float startAngle, float endAngle, bool antialiasing, bool isPieSlice ) : void
graphics CGContext
start bool
x float
y float
width float
height float
startAngle float
endAngle float
antialiasing bool
isPieSlice bool
return void
        static void make_arc(CGContext graphics, bool start, float x, float y, float width,
			         float height, float startAngle, float endAngle, bool antialiasing, bool isPieSlice)
        {
            float delta, bcp;
            double sin_alpha, sin_beta, cos_alpha, cos_beta;
            float PI = (float)Math.PI;

            float rx = width / 2;
            float ry = height / 2;

            /* center */
            float cx = x + rx;
            float cy = y + ry;

            /* angles in radians */
            float alpha = startAngle * PI / 180;
            float beta = endAngle * PI / 180;

            /* adjust angles for ellipses */
            alpha = (float)Math.Atan2(rx * Math.Sin(alpha), ry * Math.Cos(alpha));
            beta = (float)Math.Atan2(rx * Math.Sin(beta), ry * Math.Cos(beta));

            if (Math.Abs(beta - alpha) > PI)
            {
                if (beta > alpha)
                    beta -= 2 * PI;
                else
                    alpha -= 2 * PI;
            }

            delta = beta - alpha;
            bcp = (float)(4.0 / 3.0 * (1 - Math.Cos(delta / 2)) / Math.Sin(delta / 2));

            sin_alpha = Math.Sin(alpha);
            sin_beta = Math.Sin(beta);
            cos_alpha = Math.Cos(alpha);
            cos_beta = Math.Cos(beta);

            /* don't move to starting point if we're continuing an existing curve */
            if (start)
            {
                /* starting point */
                double sx = cx + rx * cos_alpha;
                double sy = cy + ry * sin_alpha;
                if (isPieSlice)
                    graphics.AddLineToPoint((float)sx,(float)sy);
                else
                    graphics.MoveTo((float)sx,(float)sy);
            }

            graphics.AddCurveToPoint(cx + rx * (float)(cos_alpha - bcp * sin_alpha),
                                    cy + ry * (float)(sin_alpha + bcp * cos_alpha),
                                    cx + rx * (float)(cos_beta + bcp * sin_beta),
                                    cy + ry * (float)(sin_beta - bcp * cos_beta),
                                    cx + rx * (float)cos_beta, cy + ry * (float)sin_beta);
        }