AdapterLib.MockLightingServiceHandler.FromAhsb C# (CSharp) Method

FromAhsb() public static method

public static FromAhsb ( float hue, float saturation, float brightness ) : Windows.UI.Color
hue float
saturation float
brightness float
return Windows.UI.Color
        public static Windows.UI.Color FromAhsb(float hue, float saturation, float brightness)
        {
            if (0f > hue
                || 360f < hue)
            {
                throw new ArgumentOutOfRangeException(
                    "hue",
                    hue,
                    "Value must be within a range of 0 - 360.");
            }

            if (0f > saturation
                || 1f < saturation)
            {
                throw new ArgumentOutOfRangeException(
                    "saturation",
                    saturation,
                    "Value must be within a range of 0 - 1.");
            }

            if (0f > brightness
                || 1f < brightness)
            {
                throw new ArgumentOutOfRangeException(
                    "brightness",
                    brightness,
                    "Value must be within a range of 0 - 1.");
            }

            if (0 == saturation)
            {
                return Windows.UI.Color.FromArgb(
                                    255,
                                    (byte)Convert.ToInt32(brightness * 255),
                                    (byte)Convert.ToInt32(brightness * 255),
                                    (byte)Convert.ToInt32(brightness * 255));
            }

            float fMax, fMid, fMin;
            int iSextant; 
              byte iMax, iMid, iMin;

            if (0.5 < brightness)
            {
                fMax = brightness - (brightness * saturation) + saturation;
                fMin = brightness + (brightness * saturation) - saturation;
            }
            else
            {
                fMax = brightness + (brightness * saturation);
                fMin = brightness - (brightness * saturation);
            }

            iSextant = (int)Math.Floor(hue / 60f);
            if (300f <= hue)
            {
                hue -= 360f;
            }

            hue /= 60f;
            hue -= 2f * (float)Math.Floor(((iSextant + 1f) % 6f) / 2f);
            if (0 == iSextant % 2)
            {
                fMid = (hue * (fMax - fMin)) + fMin;
            }
            else
            {
                fMid = fMin - (hue * (fMax - fMin));
            }

            iMax = (byte)(fMax * 255);
            iMid = (byte)(fMid * 255);
            iMin = (byte)(fMin * 255);

            switch (iSextant)
            {
                case 1:
                    return Windows.UI.Color.FromArgb(255, iMid, iMax, iMin);
                case 2:
                    return Windows.UI.Color.FromArgb(255, iMin, iMax, iMid);
                case 3:
                    return Windows.UI.Color.FromArgb(255, iMin, iMid, iMax);
                case 4:
                    return Windows.UI.Color.FromArgb(255, iMid, iMin, iMax);
                case 5:
                    return Windows.UI.Color.FromArgb(255, iMax, iMin, iMid);
                default:
                    return Windows.UI.Color.FromArgb(255, iMax, iMid, iMin);
            }
        }