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

estimateError() private method

private estimateError ( int degree, double etaA, double etaB ) : double
degree int
etaA double
etaB double
return double
        private double estimateError(int degree, double etaA, double etaB)
        {
            double eta = 0.5 * (etaA + etaB);

            if (degree < 2)
            {

                // start point
                double aCosEtaA = a * Math.Cos(etaA);
                double bSinEtaA = b * Math.Sin(etaA);
                double xA = cx + aCosEtaA * cosTheta - bSinEtaA * sinTheta;
                double yA = cy + aCosEtaA * sinTheta + bSinEtaA * cosTheta;

                // end point
                double aCosEtaB = a * Math.Cos(etaB);
                double bSinEtaB = b * Math.Sin(etaB);
                double xB = cx + aCosEtaB * cosTheta - bSinEtaB * sinTheta;
                double yB = cy + aCosEtaB * sinTheta + bSinEtaB * cosTheta;

                // maximal error point
                double aCosEta = a * Math.Cos(eta);
                double bSinEta = b * Math.Sin(eta);
                double x = cx + aCosEta * cosTheta - bSinEta * sinTheta;
                double y = cy + aCosEta * sinTheta + bSinEta * cosTheta;

                double dx = xB - xA;
                double dy = yB - yA;

                return Math.Abs(x * dy - y * dx + xB * yA - xA * yB)
                    / Math.Sqrt(dx * dx + dy * dy);

            }
            else
            {

                double x = b / a;
                double dEta = etaB - etaA;
                double cos2 = Math.Cos(2 * eta);
                double cos4 = Math.Cos(4 * eta);
                double cos6 = Math.Cos(6 * eta);

                // select the right coeficients set according to degree and b/a
                double[][][] coeffs;
                double[] safety;
                if (degree == 2)
                {
                    coeffs = (x < 0.25) ? coeffs2Low : coeffs2High;
                    safety = safety2;
                }
                else
                {
                    coeffs = (x < 0.25) ? coeffs3Low : coeffs3High;
                    safety = safety3;
                }

                double c0 = rationalFunction(x, coeffs[0][0])
                    + cos2 * rationalFunction(x, coeffs[0][1])
                        + cos4 * rationalFunction(x, coeffs[0][2])
                        + cos6 * rationalFunction(x, coeffs[0][3]);

                double c1 = rationalFunction(x, coeffs[1][0])
                    + cos2 * rationalFunction(x, coeffs[1][1])
                        + cos4 * rationalFunction(x, coeffs[1][2])
                        + cos6 * rationalFunction(x, coeffs[1][3]);

                return rationalFunction(x, safety) * a * Math.Exp(c0 + c1 * dEta);

            }
        }