{"record":{"id":"11af567502ebcb7a","repo":"dotnet/wpf","slug":"sr-invaliddiameter-strokecollection2","errorCode":null,"errorMessage":"SR.InvalidDiameter","messagePattern":"SR\\.InvalidDiameter","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs","lineNumber":66,"sourceCode":"        /// Tap-hit. Hit tests all strokes within a point, and returns a StrokeCollection for these strokes.Internally does Stroke.HitTest(Point, 1pxlRectShape).\n        /// </summary>\n        /// <returns>A StrokeCollection that either empty or contains the top hit stroke</returns>\n        public StrokeCollection HitTest(Point point)\n        {\n            return PointHitTest(point, new RectangleStylusShape(1f, 1f));\n        }\n\n        /// <summary>\n        /// Tap-hit\n        /// </summary>\n        /// <param name=\"point\">The central point</param>\n        /// <param name=\"diameter\">The diameter value of the circle</param>\n        /// <returns>A StrokeCollection that either empty or contains the top hit stroke</returns>\n        public StrokeCollection 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 PointHitTest(point, new EllipseStylusShape(diameter, diameter));\n        }\n\n        /// <summary>\n        /// Hit-testing with lasso\n        /// </summary>\n        /// <param name=\"lassoPoints\">points making the lasso</param>\n        /// <param name=\"percentageWithinLasso\">the margin value to tell whether a stroke\n        /// is in or outside of the rect</param>\n        /// <returns>collection of strokes found inside the rectangle</returns>\n        public StrokeCollection HitTest(IEnumerable<Point> lassoPoints, int percentageWithinLasso)\n        {\n            // Check the input parameters\n            ArgumentNullException.ThrowIfNull(lassoPoints);\n            if ((percentageWithinLasso < 0) || (percentageWithinLasso > 100))\n            {\n                throw new System.ArgumentOutOfRangeException(nameof(percentageWithinLasso));","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs#L48-L84","documentation":"StrokeCollection.HitTest(Point, double diameter) validates the circle diameter against DrawingAttributes.MinWidth/MaxWidth before performing the point hit test. A diameter that is NaN, below MinWidth, or above MaxWidth is rejected with ArgumentOutOfRangeException. The diameter defines the size of the hit-test circle.","triggerScenarios":"Calling HitTest(point, diameter) with double.NaN, a negative/zero diameter, or a diameter larger than DrawingAttributes.MaxWidth (e.g. passing a computed value from a scale transform that overflowed or a UI value in the wrong unit).","commonSituations":"Binding the diameter to a zoom slider that can reach 0 or NaN (NaN from 0/0 division), or passing a radius where a diameter is expected, or mixing device pixels with device-independent units.","solutions":["Clamp the diameter: Math.Max(DrawingAttributes.MinWidth, Math.Min(DrawingAttributes.MaxWidth, d))","Validate before the call: !double.IsNaN(d) && d >= DrawingAttributes.MinWidth && d <= DrawingAttributes.MaxWidth","Check the source of the diameter value for NaN propagation from division by zero"],"exampleFix":"// before\nvar hits = strokes.HitTest(point, userRadius * 2 * zoom); // may be NaN/huge\n// after\nvar d = Math.Clamp(userRadius * 2 * zoom, DrawingAttributes.MinWidth, DrawingAttributes.MaxWidth);\nif (!double.IsNaN(d)) { var hits = strokes.HitTest(point, d); }","handlingStrategy":"validation","validationCode":"if (double.IsNaN(diameter) || diameter < DrawingAttributes.MinWidth || diameter > DrawingAttributes.MaxWidth) return new StrokeCollection();","typeGuard":null,"tryCatchPattern":"try { return strokes.HitTest(point, d); } catch (ArgumentOutOfRangeException) { return new StrokeCollection(); }","preventionTips":["Clamp diameters to DrawingAttributes.MinWidth/MaxWidth","Check for NaN whenever the value is computed by division","Never pass a radius where a diameter is expected"],"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-21T21:30:21.729Z"}