aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/Colourful/Implementation/Conversion/LChab/LChabToLabConverter.cs
blob: e607ae6e590843808bc158d6a099abe22073bb59 (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="LChabColor" /> to <see cref="LabColor" />.
    /// </summary>
    public sealed class LChabToLabConverter : IColorConversion<LChabColor, LabColor>
    {
        /// <summary>
        /// Default singleton instance of the converter.
        /// </summary>
        public static readonly LChabToLabConverter Default = new LChabToLabConverter();

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

            var a = C * Math.Cos(hRadians);
            var b = C * Math.Sin(hRadians);

            var output = new LabColor(L, a, b, input.WhitePoint);
            return output;
        }

        #region Overrides

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

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

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

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

        #endregion
    }
}