aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/Colourful/Implementation/Conversion/LChab/LabToLChabConverter.cs
blob: 39bb80d0b2d163aa48b2e5f08657db2aa4db7475 (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
using System;

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

        /// <summary>
        /// Converts from <see cref="LabColor" /> to <see cref="LChabColor" />.
        /// </summary>
        public LChabColor Convert(in LabColor input)
        {
            double L = input.L, a = input.a, b = input.b;
            var C = Math.Sqrt(a * a + b * b);
            var hRadians = Math.Atan2(b, a);
            var hDegrees = Angle.NormalizeDegree(Angle.RadianToDegree(hRadians));

            var output = new LChabColor(L, C, hDegrees, input.WhitePoint);
            return output;
        }

        #region Overrides

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

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

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

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

        #endregion
    }
}