{"record":{"id":"c3304f64b5770edd","repo":"dotnet/wpf","slug":"sr-invaliddiameter","errorCode":null,"errorMessage":"SR.InvalidDiameter","messagePattern":"SR\\.InvalidDiameter","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke2.cs","lineNumber":195,"sourceCode":"        /// </summary>\n        /// <param name=\"point\">The location to do the hitest</param>\n        /// <returns>True is this stroke is hit, false otherwise</returns>\n        public bool HitTest(Point point)\n        {\n            return HitTest(new Point[]{point}, new EllipseStylusShape(TapHitPointSize, TapHitPointSize, TapHitRotation));\n        }\n\n        /// <summary>\n        /// Tap-hit. Hit tests with a point.\n        /// </summary>\n        /// <param name=\"point\">The location to do the hittest</param>\n        /// <param name=\"diameter\">diameter of the tip</param>\n        /// <returns>true if hit, false otherwise</returns>\n        public bool HitTest(Point point, double diameter)\n        {\n            if (Double.IsNaN(diameter) || diameter < DrawingAttributes.MinWidth || diameter > DrawingAttributes.MaxWidth)\n            {\n                throw new ArgumentOutOfRangeException(nameof(diameter), SR.InvalidDiameter);\n            }\n            return HitTest(new Point[]{point}, new EllipseStylusShape(diameter, diameter, TapHitRotation));\n        }\n\n        /// <summary>\n        /// Check whether a certain percentage of the stroke is within the Rect passed in.\n        /// </summary>\n        /// <param name=\"bounds\"></param>\n        /// <param name=\"percentageWithinBounds\"></param>\n        /// <returns></returns>\n        public bool HitTest(Rect bounds, int percentageWithinBounds)\n        {\n            if ((percentageWithinBounds < 0) || (percentageWithinBounds > 100))\n            {\n                throw new System.ArgumentOutOfRangeException(nameof(percentageWithinBounds));\n            }\n\n            if (percentageWithinBounds == 0)","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke2.cs#L177-L213","documentation":"Stroke.HitTest(Point, double diameter) validates the tip diameter used to simulate a tap hit. It throws ArgumentOutOfRangeException(SR.InvalidDiameter) when diameter is NaN, below DrawingAttributes.MinWidth, or above DrawingAttributes.MaxWidth. The diameter must be a real width within the allowed attribute range.","triggerScenarios":"Calling HitTest(point, double.NaN); calling with diameter 0 or negative; calling with a diameter exceeding DrawingAttributes.MaxWidth.","commonSituations":"Binding a slider/zoom factor to the tip diameter without clamping; NaN from a failed calculation or uninitialized double passed as the tip size.","solutions":["Clamp diameter between DrawingAttributes.MinWidth and DrawingAttributes.MaxWidth before calling","Check double.IsNaN(diameter) and substitute a default (e.g. DrawingAttributes.MinWidth)","Bind the UI control feeding the diameter with min/max limits"],"exampleFix":"// before\nbool hit = stroke.HitTest(pt, diameter);\n// after\ndouble d = double.IsNaN(diameter) ? DrawingAttributes.MinWidth : Math.Clamp(diameter, DrawingAttributes.MinWidth, DrawingAttributes.MaxWidth);\nbool hit = stroke.HitTest(pt, d);","handlingStrategy":"validation","validationCode":"bool valid = !double.IsNaN(diameter) && diameter >= DrawingAttributes.MinWidth && diameter <= DrawingAttributes.MaxWidth;","typeGuard":"static bool IsValidDiameter(double d) => !double.IsNaN(d) && d >= DrawingAttributes.MinWidth && d <= DrawingAttributes.MaxWidth;","tryCatchPattern":"try { hit = stroke.HitTest(point, d); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"diameter\") { hit = stroke.HitTest(point, DrawingAttributes.MinWidth); }","preventionTips":["Clamp tip sizes with Math.Clamp against MinWidth/MaxWidth","Check for NaN from upstream computations","Constrain UI controls that feed the diameter"],"tags":["wpf","ink","argument-out-of-range","hit-test"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}