{"record":{"id":"41b817574dabcb7b","repo":"TheAlgorithms/C-Sharp","slug":"nameof-hue-should-be-between-0-and-360","errorCode":null,"errorMessage":"{nameof(hue)} should be between 0 and 360","messagePattern":"(.+?) should be between 0 and 360","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Other/RGBHSVConversion.cs","lineNumber":30,"sourceCode":"///     https://en.wikipedia.org/wiki/HSL_and_HSV).\n/// </summary>\npublic static class RgbHsvConversion\n{\n    /// <summary>\n    ///     Conversion from the HSV-representation to the RGB-representation.\n    /// </summary>\n    /// <param name=\"hue\">Hue of the color.</param>\n    /// <param name=\"saturation\">Saturation of the color.</param>\n    /// <param name=\"value\">Brightness-value of the color.</param>\n    /// <returns>The tuple of RGB-components.</returns>\n    public static (byte Red, byte Green, byte Blue) HsvToRgb(\n        double hue,\n        double saturation,\n        double value)\n    {\n        if (hue < 0 || hue > 360)\n        {\n            throw new ArgumentOutOfRangeException(nameof(hue), $\"{nameof(hue)} should be between 0 and 360\");\n        }\n\n        if (saturation < 0 || saturation > 1)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(saturation),\n                $\"{nameof(saturation)} should be between 0 and 1\");\n        }\n\n        if (value < 0 || value > 1)\n        {\n            throw new ArgumentOutOfRangeException(nameof(value), $\"{nameof(value)} should be between 0 and 1\");\n        }\n\n        var chroma = value * saturation;\n        var hueSection = hue / 60;\n        var secondLargestComponent = chroma * (1 - Math.Abs(hueSection % 2 - 1));\n        var matchValue = value - chroma;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Other/RGBHSVConversion.cs#L12-L48","documentation":"RGBHSVConversion.HsvToRgb converts HSV color components to RGB and requires hue to be in the [0, 360] degree range. Values outside that range are rejected with ArgumentOutOfRangeException before conversion. The library does not normalize hue; callers must pass canonical degrees.","triggerScenarios":"Calling HsvToRgb with hue < 0 or hue > 360, e.g. HsvToRgb(-30, 0.5, 0.5) or HsvToRgb(400, 1, 1), commonly from hue values accumulated past 360 or computed on a -180..180 scale.","commonSituations":"Hue read from color pickers or sensors that report negative or >360 values; averaging or adding hues without modulo 360; mixing radian-based hue with this degree-based API.","solutions":["Wrap the hue into [0, 360) with modulo before calling, e.g. ((hue % 360) + 360) % 360","Convert radian-based hues to degrees before invoking","Validate the hue range at the boundary where the value enters your code"],"exampleFix":"// before\nvar rgb = RGBHSVConversion.HsvToRgb(hue, sat, val);\n// after\nhue = ((hue % 360) + 360) % 360;\nvar rgb = RGBHSVConversion.HsvToRgb(hue, sat, val);","handlingStrategy":"validation","validationCode":"if (hue < 0 || hue > 360) throw new ArgumentException(\"hue must be in [0, 360]\", nameof(hue));","typeGuard":"static bool IsValidHue(double hue) => hue >= 0 && hue <= 360;","tryCatchPattern":"try { var rgb = RGBHSVConversion.HsvToRgb(hue, sat, val); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"hue\")\n{\n    hue = ((hue % 360) + 360) % 360; // normalize and retry\n}","preventionTips":["Normalize hue with modulo 360 whenever hues are accumulated or averaged","Confirm whether your hue source uses degrees or radians before calling","Validate saturation in [0,1] and value in [0,1] alongside hue"],"tags":["argument-out-of-range","color","hsv","csharp"],"backgroundTag":"value-out-of-range","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}