aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/Colourful/Implementation/Conversion/LChuv/LChuvToLuvConverter.cs
blob: ef8c06d0b436aea30a932074796d0cd6c7480a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;

namespace Colourful.Implementation.Conversion
{
    /// <summary>
    /// Converts from <see cref="LChuvColor" /> to <see cref="LuvColor" />.
    /// </summary>
    public sealed class LChuvToLuvConverter : IColorConversion<LChuvColor, LuvColor>
    {
        /// <summary>
        /// Default singleton instance of the converter.
        /// </summary>
        public static readonly LChuvToLuvConverter Default = new LChuvToLuvConverter();

        /// <summary>
        /// Converts from <see cref="LChuvColor" /> to <see cref="LuvColor" />.
        /// </summary>
        public LuvColor Convert(in LChuvColor input)
        {
            double L = input.L, C = input.C, hDegrees = input.h;
            var hRadians = Angle.DegreeToRadian(hDegrees);

            var u = C * Math.Cos(hRadians);
            var v = C * Math.Sin(hRadians);

            var output = new LuvColor(L, u, v, input.WhitePoint);
            return output;
        }

        #region Overrides

        /// <inheritdoc cref="object" />
        public override bool Equals(object obj) => obj is LChuvToLuvConverter;

        /// <inheritdoc cref="object" />
        public override int GetHashCode() => 1;

        /// <inheritdoc cref="object" />
        public static bool operator ==(LChuvToLuvConverter left, LChuvToLuvConverter right) => Equals(left, right);

        /// <inheritdoc cref="object" />
        public static bool operator !=(LChuvToLuvConverter left, LChuvToLuvConverter right) => !Equals(left, right);

        #endregion
    }
}