{"record":{"id":"61c351a8a0a8a7d1","repo":"AvaloniaUI/Avalonia","slug":"degree-should-be-between-1-and-maxdegree","errorCode":null,"errorMessage":"degree should be between {1} and {_maxDegree}","messagePattern":"degree should be between (.+?) and (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/PreciseEllipticArcHelper.cs","lineNumber":566,"sourceCode":"            /// <param name=\"x\">Abscissa for which the value should be computed</param>\n            /// <param name=\"c\">Coefficients array of the rational function</param>\n            /// <returns></returns>\n            private static double RationalFunction(double x, double[] c)\n            {\n                return (x * (x * c[0] + c[1]) + c[2]) / (x + c[3]);\n            }\n\n            /// <summary>\n            /// Estimate the approximation error for a sub-arc of the instance\n            /// </summary>\n            /// <param name=\"degree\">Degree of the Bezier curve to use (1, 2 or 3)</param>\n            /// <param name=\"etaA\">Start angle of the sub-arc</param>\n            /// <param name=\"etaB\">End angle of the sub-arc</param>\n            /// <returns>Upper bound of the approximation error between the Bezier curve and the real ellipse</returns>\n            public double EstimateError(int degree, double etaA, double etaB)\n            {\n                if (degree < 1 || degree > _maxDegree)\n                    throw new ArgumentException($\"degree should be between {1} and {_maxDegree}\", nameof(degree));\n                double eta = 0.5 * (etaA + etaB);\n                if (degree < 2)\n                {\n                    //start point\n                    double aCosEtaA = A * Math.Cos(etaA);\n                    double bSinEtaA = B * Math.Sin(etaA);\n                    double xA = Cx + aCosEtaA * _cosTheta - bSinEtaA * _sinTheta;\n                    double yA = Cy + aCosEtaA * _sinTheta + bSinEtaA * _cosTheta;\n\n                    //end point\n                    double aCosEtaB = A * Math.Cos(etaB);\n                    double bSinEtaB = B * Math.Sin(etaB);\n                    double xB = Cx + aCosEtaB * _cosTheta - bSinEtaB * _sinTheta;\n                    double yB = Cy + aCosEtaB * _sinTheta + bSinEtaB * _cosTheta;\n\n                    //maximal error point\n                    double aCosEta = A * Math.Cos(eta);\n                    double bSinEta = B * Math.Sin(eta);","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/PreciseEllipticArcHelper.cs#L548-L584","documentation":"Thrown by EstimateError when the requested Bezier degree is less than 1 or greater than the helper's current _maxDegree (set via SetMaxDegree, default 3). The error-estimation branches only handle degrees 1, 2, and 3 up to the configured maximum, so out-of-range degrees have no formula. The message interpolates the actual allowed upper bound, so it reads e.g. 'degree should be between 1 and 3'.","triggerScenarios":"arc.EstimateError(0, etaA, etaB), arc.EstimateError(4, etaA, etaB), or calling with degree 3 after SetMaxDegree(2).","commonSituations":"Looping over candidate degrees without bounds; calling EstimateError with a degree higher than the configured max; passing an uninitialized degree variable (0).","solutions":["Pass a degree in [1, _maxDegree]; check the current max via the value you set with SetMaxDegree.","Loop only over valid degrees: for (int d = 1; d <= maxDegree; d++) ... and pick the smallest whose error is under threshold.","Initialize degree explicitly rather than relying on default(int) (0)."],"exampleFix":"// before\nfor (int d = 0; d <= 4; d++)\n    err = arc.EstimateError(d, a, b);\n\n// after\nfor (int d = 1; d <= maxDegree; d++)\n    err = arc.EstimateError(d, a, b);","handlingStrategy":"validation","validationCode":"var d = Math.Clamp(degree, 1, maxDegree);\nvar err = arc.EstimateError(d, etaA, etaB);","typeGuard":"static bool IsValidDegree(int d, int max) => d >= 1 && d <= max;","tryCatchPattern":null,"preventionTips":["Loop degrees in [1, maxDegree] only.","Keep the degree you pass to EstimateError consistent with SetMaxDegree."],"tags":["avalonia","arc","bezier","argument","error-estimation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}