1
- /**
1
+ /*
2
2
* The MIT License (MIT)
3
3
* Copyright (c) 2014 Andrés Correa Casablanca
4
4
*
21
21
* SOFTWARE.
22
22
*/
23
23
24
- /**
25
- * Contributors:
26
- * - Andrés Correa Casablanca <castarco@gmail.com , castarco@litipk.com>
27
- */
24
+ /*
25
+ * Contributors:
26
+ * - Andrés Correa Casablanca <castarco@gmail.com , castarco@litipk.com>
27
+ */
28
28
29
29
30
30
using System ;
@@ -38,32 +38,46 @@ namespace Litipk.ColorSharp
38
38
namespace ColorSpaces
39
39
{
40
40
/**
41
- * CIE 1931 (2º) xyY Color Space.
41
+ * <summary> CIE's 1931 (2º) xyY Color Space.</summary>
42
42
*/
43
- public class CIExyY : AConvertibleColor
43
+ public sealed class CIExyY : AConvertibleColor
44
44
{
45
- #region readonly properties
46
45
47
- public readonly double x , y , Y ;
46
+ #region properties
48
47
49
- static readonly xyYPoint nullP = new xyYPoint { x = - 1.0 , y = - 1.0 } ;
50
- static readonly xyYPoint RsRGB = new xyYPoint { x = 0.640074499456775 , y = 0.329970510631693 } ;
51
- static readonly xyYPoint GsRGB = new xyYPoint { x = 0.3 , y = 0.6 } ;
52
- static readonly xyYPoint BsRGB = new xyYPoint { x = 0.150016622340426 , y = 0.0600066489361702 } ;
48
+ #region static properties
49
+ // Light wavelengths coordinates in the CIE's 1931 xyY color sapce.
50
+ static xyYPoint [ ] Sharkfin ;
53
51
52
+ // Sharkfin transformation with performance purposes.
53
+ static xyYPoint [ ] SortedSharkfin ;
54
54
#endregion
55
55
56
+ #region readonly properties
57
+ /**
58
+ * <value>x component of the CIE's 1931 color space : X/(X+Y+Z) .</value>
59
+ */
60
+ public readonly double x ;
56
61
57
- #region static properties
62
+ /**
63
+ * <value>y component of the CIE's 1931 color space : Y/(X+Y+Z) .</value>
64
+ */
65
+ public readonly double y ;
58
66
59
- static xyYPoint [ ] Sharkfin ;
60
- static xyYPoint [ ] SortedSharkfin ;
67
+ /**
68
+ * <value>Y component of the CIE's 1931 color space. The same Y from CIE's 1931 XYZ color space.</value>
69
+ */
70
+ public readonly double Y ;
71
+ #endregion
61
72
62
73
#endregion
63
74
64
75
65
76
#region constructors
66
77
78
+ /**
79
+ * Static members initialization
80
+ */
67
81
static CIExyY ( )
68
82
{
69
83
var mfX = CIE1931XYZ5NmMatchingFunctionX . Instance . Amplitudes ;
@@ -84,19 +98,27 @@ static CIExyY()
84
98
Array . Sort ( SortedSharkfin , new xyYPointComparer ( ) ) ;
85
99
}
86
100
101
+ /**
102
+ * <summary>HACK: DONT' USE this constructor.</summary>
103
+ */
87
104
public CIExyY ( ) {
88
105
Conversors . Add ( typeof ( CIEXYZ ) , ToXYZ ) ;
89
106
}
90
107
91
- protected CIExyY ( AConvertibleColor dataSource = null ) : base ( dataSource ) {
92
- Conversors . Add ( typeof ( CIEXYZ ) , ToXYZ ) ;
93
- }
94
-
95
- public CIExyY ( double x , double y , double Y , AConvertibleColor dataSource = null ) : this ( dataSource )
108
+ /**
109
+ * <summary>Creates a new color sample in the CIE's 1931 xyY color space</summary>
110
+ * <param name="x">CIE's 1931 xyY x coordinate</param>
111
+ * <param name="y">CIE's 1931 xyY y coordinate</param>
112
+ * <param name="Y">Lightness parameter</param>
113
+ * <param name="dataSource">If you aren't working with ColorSharp internals, don't use this parameter</param>
114
+ */
115
+ public CIExyY ( double x , double y , double Y , AConvertibleColor dataSource = null ) : base ( dataSource )
96
116
{
97
117
this . x = x ;
98
118
this . y = y ;
99
119
this . Y = Y ;
120
+
121
+ Conversors . Add ( typeof ( CIEXYZ ) , ToXYZ ) ;
100
122
}
101
123
102
124
#endregion
@@ -114,6 +136,9 @@ public CIEXYZ ToXYZ (ConversionStrategy strategy=ConversionStrategy.Default)
114
136
115
137
#region inherited methods
116
138
139
+ /**
140
+ * <inheritdoc />
141
+ */
117
142
public override bool IsInsideColorSpace ( )
118
143
{
119
144
// Fast checks
@@ -134,7 +159,43 @@ public override bool IsInsideColorSpace()
134
159
}
135
160
136
161
/**
137
- * Monotone Chain algorithm
162
+ * <inheritdoc />
163
+ */
164
+ public override bool Equals ( Object obj )
165
+ {
166
+ CIExyY xyYObj = obj as CIExyY ;
167
+
168
+ if ( xyYObj == null || GetHashCode ( ) != obj . GetHashCode ( ) )
169
+ return false ;
170
+
171
+ return (
172
+ Math . Abs ( x - xyYObj . x ) <= double . Epsilon &&
173
+ Math . Abs ( y - xyYObj . y ) <= double . Epsilon &&
174
+ Math . Abs ( Y - xyYObj . Y ) <= double . Epsilon
175
+ ) ;
176
+ }
177
+
178
+ /**
179
+ * <inheritdoc />
180
+ */
181
+ public override int GetHashCode ( )
182
+ {
183
+ int hash = 19 ;
184
+
185
+ hash = hash * 31 + x . GetHashCode ( ) ;
186
+ hash = hash * 31 + y . GetHashCode ( ) ;
187
+ hash = hash * 31 + Y . GetHashCode ( ) ;
188
+
189
+ return hash ;
190
+ }
191
+
192
+ #endregion
193
+
194
+ #region internal utilities
195
+
196
+ /**
197
+ * Monotone Chain algorithm. See
198
+ * http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
138
199
*/
139
200
static xyYPoint [ ] findConvexHull ( xyYPoint [ ] points )
140
201
{
@@ -162,34 +223,13 @@ static xyYPoint[] findConvexHull(xyYPoint[] points)
162
223
return tmpHull ;
163
224
}
164
225
226
+ /**
227
+ * Used inside findConvexHull method.
228
+ */
165
229
static double cross ( xyYPoint O , xyYPoint A , xyYPoint B ) {
166
230
return ( A . x - O . x ) * ( B . y - O . y ) - ( A . y - O . y ) * ( B . x - O . x ) ;
167
231
}
168
232
169
- public override bool Equals ( Object obj )
170
- {
171
- CIExyY xyYObj = obj as CIExyY ;
172
-
173
- if ( xyYObj == null || GetHashCode ( ) != obj . GetHashCode ( ) )
174
- return false ;
175
-
176
- return (
177
- Math . Abs ( x - xyYObj . x ) <= double . Epsilon &&
178
- Math . Abs ( y - xyYObj . y ) <= double . Epsilon &&
179
- Math . Abs ( Y - xyYObj . Y ) <= double . Epsilon
180
- ) ;
181
- }
182
- public override int GetHashCode ( )
183
- {
184
- int hash = 19 ;
185
-
186
- hash = hash * 31 + x . GetHashCode ( ) ;
187
- hash = hash * 31 + y . GetHashCode ( ) ;
188
- hash = hash * 31 + Y . GetHashCode ( ) ;
189
-
190
- return hash ;
191
- }
192
-
193
233
#endregion
194
234
}
195
235
}
0 commit comments