Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 1ec799f

Browse files
committed
A lot of code cleanups
1 parent e1df83a commit 1ec799f

File tree

12 files changed

+142
-40
lines changed

12 files changed

+142
-40
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
ColorSharp's Changelog
22
======================
33

4+
## 2014-11-05 : 0.7.0 Release
5+
6+
### Contributors
7+
* Andrés Correa Casablanca <castarco@gmail.com , castarco@litipk.com>
8+
9+
### Changes
10+
* Improved XML documentation.
11+
* Removed many build warnings (related with XML documentation).
12+
* Sealed many classes.
13+
* Big refactor:
14+
* Removed the colors conversion path search mechanism.
15+
* Now is less flexible, but more efficient and simple.
16+
* Now it's better to use the non type-parametric conversion methods.
17+
* **WARNING:** Now we assume that Y=1 in CIE's xyY or XYZ color spaces is the luminance of the white point.
18+
* **WARNING:** Breaks API.
19+
20+
### Bugfixes
21+
* Bugfix in sRGB->CIE's 1931 XYZ conversion (the gamma correction was done after the lineal transformation)
22+
23+
424
## 2014-11-05 : 0.6.0 Release
525

626
### Contributors

ColorSharp.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ Global
3434
$0.VersionControlPolicy = $2
3535
$2.inheritsSet = Mono
3636
description = A .Net/Mono library to handle color spaces (and light spectrums!)
37-
version = 0.6.0
37+
version = 0.7.0
3838
EndGlobalSection
3939
EndGlobal

ColorSharp/ColorSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<SignAssembly>true</SignAssembly>
1212
<DelaySign>false</DelaySign>
1313
<AssemblyOriginatorKeyFile>colorsharp.snk</AssemblyOriginatorKeyFile>
14-
<ReleaseVersion>0.6.0</ReleaseVersion>
14+
<ReleaseVersion>0.7.0</ReleaseVersion>
1515
</PropertyGroup>
1616
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1717
<DebugSymbols>true</DebugSymbols>

ColorSharp/ColorSharp.nuspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>$description$</description>
1313
<releaseNotes>
14-
- Improved documentation
15-
- Minor cleanups
16-
- Bugfix in sRGB -> CIE's 1931 XYZ conversion
14+
- Improved documentation
15+
- Minor cleanups
16+
- Big refactor
17+
- Removed NUnit dependency
1718
</releaseNotes>
1819
<copyright>Copyright 2014</copyright>
1920
<tags>Light Color Colour CIEXYZ CIExyY sRGB</tags>

ColorSharp/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
4747
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
4848

49-
[assembly: AssemblyVersion ("0.6.0.*")]
49+
[assembly: AssemblyVersion ("0.7.0.*")]
5050

5151
// The following attributes are used to specify the signing key for the assembly,
5252
// if desired. See the Mono documentation for more information about signing.

ColorSharp/src/ColorSpaces/AConvertibleColor.cs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,26 @@ namespace Litipk.ColorSharp
3535
{
3636
namespace ColorSpaces
3737
{
38+
/**
39+
*
40+
*/
3841
public abstract class AConvertibleColor
3942
{
4043
#region properties
4144

42-
// If this "color" comes from another data source, then we keep the original data.
43-
protected AConvertibleColor DataSource = null;
45+
/**
46+
* <value>Original color sample</value>
47+
*/
48+
public readonly AConvertibleColor DataSource = null;
4449

4550
#endregion
4651

4752

4853
#region constructors
4954

50-
// TODO: Check if this should be public in order to work as expected with reflection.
55+
/**
56+
* Boilerplate constructor
57+
*/
5158
protected AConvertibleColor(AConvertibleColor dataSource = null)
5259
{
5360
DataSource = dataSource;
@@ -58,37 +65,49 @@ protected AConvertibleColor(AConvertibleColor dataSource = null)
5865

5966
#region conversion skeleton
6067

68+
/**
69+
* <see cref="ConvertTo"/>
70+
*/
6171
public T ConvertTo<T> (ConversionStrategy strategy=ConversionStrategy.Default) where T : AConvertibleColor
6272
{
63-
Type t = typeof(T);
73+
return (T)ConvertTo (typeof(T), strategy);
74+
}
75+
76+
/**
77+
* <summary>Method that allows conversions passing the type as a parameter.</summary>
78+
* <remarks>DON'T USE it to implement conversion methods, use the non type-parametric variants.</remarks>
79+
*/
80+
public AConvertibleColor ConvertTo (Type t, ConversionStrategy strategy=ConversionStrategy.Default)
81+
{
6482
Type tt = GetType ();
6583

6684
if (t == tt) {
6785
// Dumb conversion
68-
return (T)(AConvertibleColor)this;
86+
return this;
6987
}
7088

7189
if (DataSource != null) {
7290
if (DataSource.GetType () == t) {
73-
return (T)DataSource;
91+
return DataSource;
7492
}
7593

76-
return DataSource.ConvertTo<T> (strategy);
94+
return DataSource.ConvertTo(t, strategy);
7795
}
7896

79-
return InnerConvertTo<T> (strategy);
97+
return InnerConvertTo(t, strategy);
8098
}
8199

82-
protected T InnerConvertTo<T> (ConversionStrategy strategy = ConversionStrategy.Default) where T : AConvertibleColor
100+
/**
101+
* Helper method used by ConvertTo.
102+
*/
103+
private AConvertibleColor InnerConvertTo (Type t, ConversionStrategy strategy = ConversionStrategy.Default)
83104
{
84-
Type t = typeof(T);
85-
86105
if (t == typeof(CIEXYZ))
87-
return (T)(AConvertibleColor)ToCIEXYZ (strategy);
106+
return ToCIEXYZ (strategy);
88107
if (t == typeof(CIExyY))
89-
return (T)(AConvertibleColor)ToCIExyY(strategy);
108+
return ToCIExyY(strategy);
90109
if (t == typeof(SRGB))
91-
return (T)(AConvertibleColor)ToSRGB (strategy);
110+
return ToSRGB (strategy);
92111

93112
throw new NotImplementedException ("This conversion isn't implemented.");
94113
}
@@ -114,7 +133,7 @@ protected T InnerConvertTo<T> (ConversionStrategy strategy = ConversionStrategy.
114133
public abstract CIExyY ToCIExyY (ConversionStrategy strategy = ConversionStrategy.Default);
115134

116135
/**
117-
* <summary>Converts the color sample to an HP's & Microsoft's 1996 sRGB sample.</summary>
136+
* <summary>Converts the color sample to an HP's and Microsoft's 1996 sRGB sample.</summary>
118137
*/
119138
public abstract SRGB ToSRGB(ConversionStrategy strategy = ConversionStrategy.Default);
120139

ColorSharp/src/ColorSpaces/SRGB.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,39 @@ namespace Litipk.ColorSharp
3636
namespace ColorSpaces
3737
{
3838
/**
39-
* <summary>HP's & Microsoft's 1996 sRGB Color Space.</summary>
39+
* <summary>HP's and Microsoft's 1996 sRGB Color Space.</summary>
4040
*/
4141
public sealed class SRGB : AConvertibleColor
4242
{
4343
#region private properties
4444

45-
public readonly double R, G, B;
45+
/**
46+
* <value>Red component</value>
47+
*/
48+
public readonly double R;
49+
50+
/**
51+
* <value>Green component</value>
52+
*/
53+
public readonly double G;
54+
55+
/**
56+
* <value>Blue component</value>
57+
*/
58+
public readonly double B;
4659

4760
#endregion
4861

4962

5063
#region constructors
5164

65+
/**
66+
* <summary>Creates a new color sample in the sRGB color space</summary>
67+
* <param name="R">Red component (between 0 and 1)</param>
68+
* <param name="G">Green component (between 0 and 1)</param>
69+
* <param name="B">Blue component (between 0 and 1)</param>
70+
* <param name="dataSource">If you aren't working with ColorSharp internals, don't use this parameter</param>
71+
*/
5272
public SRGB (double R, double G, double B, AConvertibleColor dataSource=null) : base(dataSource)
5373
{
5474
this.R = R;
@@ -61,6 +81,9 @@ public SRGB (double R, double G, double B, AConvertibleColor dataSource=null) :
6181

6282
#region AConvertibleColor methods
6383

84+
/**
85+
* <inheritdoc />
86+
*/
6487
public override bool IsInsideColorSpace()
6588
{
6689
return (
@@ -71,8 +94,8 @@ public override bool IsInsideColorSpace()
7194
}
7295

7396
/**
74-
* Converts the HP's & Microsoft's 1996 sRGB sample to a CIE 1931 XYZ sample
75-
*/
97+
* <inheritdoc />
98+
*/
7699
public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.Default)
77100
{
78101
// Gamma correction
@@ -89,11 +112,17 @@ public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.
89112
);
90113
}
91114

115+
/**
116+
* <inheritdoc />
117+
*/
92118
public override CIExyY ToCIExyY (ConversionStrategy strategy = ConversionStrategy.Default)
93119
{
94120
return ToCIEXYZ ().ToCIExyY ();
95121
}
96122

123+
/**
124+
* <inheritdoc />
125+
*/
97126
public override SRGB ToSRGB (ConversionStrategy strategy = ConversionStrategy.WaveLength5NmStep)
98127
{
99128
return this;
@@ -104,6 +133,9 @@ public override SRGB ToSRGB (ConversionStrategy strategy = ConversionStrategy.Wa
104133

105134
#region Object methods
106135

136+
/**
137+
* <inheritdoc />
138+
*/
107139
public override bool Equals(Object obj)
108140
{
109141
SRGB srgbObj = obj as SRGB;
@@ -117,6 +149,10 @@ public override bool Equals(Object obj)
117149
Math.Abs (B - srgbObj.B) <= double.Epsilon
118150
);
119151
}
152+
153+
/**
154+
* <inheritdoc />
155+
*/
120156
public override int GetHashCode ()
121157
{
122158
int hash = 17;

ColorSharp/src/InternalUtils/Comparers.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,14 @@ namespace Litipk.ColorSharp
3535
{
3636
namespace InternalUtils
3737
{
38-
/**
39-
* Internal Class
40-
*/
41-
class KeyValuePairComparer : IComparer<KeyValuePair<double, double>> {
38+
sealed class KeyValuePairComparer : IComparer<KeyValuePair<double, double>> {
4239
public int Compare(KeyValuePair<double, double> a, KeyValuePair<double, double> b)
4340
{
4441
return Math.Abs (a.Key - b.Key) <= double.Epsilon ? 0 : a.Key.CompareTo (b.Key);
4542
}
4643
}
4744

48-
class xyYPointComparer : IComparer<xyYPoint> {
45+
sealed class xyYPointComparer : IComparer<xyYPoint> {
4946
public int Compare(xyYPoint a, xyYPoint b)
5047
{
5148
return (a.x == b.x) ?

ColorSharp/src/LightSpectrums/ALightSpectrum.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,43 @@ namespace Litipk.ColorSharp
3939

4040
namespace LightSpectrums
4141
{
42+
/**
43+
* <summary>Abstract class that provides basic methods to manipulate light spectrums.</summary>
44+
*/
4245
public abstract class ALightSpectrum : AConvertibleColor, IRealFunctionWithFiniteSupport
4346
{
47+
/**
48+
* Boilerplate constructor
49+
*/
4450
protected ALightSpectrum(AConvertibleColor dataSource=null) : base(dataSource) { }
4551

46-
#region inheritable methods
52+
#region abstract methods
4753

4854
#region IRealFunctionWithFiniteSupport methods
4955

5056
/**
51-
* This gives us the wave amplitude at a given wave length, if it's necessary the method will do interpolation.
57+
* <inheritdoc />
5258
*/
5359
public abstract double EvaluateAt(double waveLength);
5460

55-
// Analytic aproximations also have their confidence intervals, so
56-
// there aren't exceptional cases here.
61+
/**
62+
* <inheritdoc />
63+
*/
5764
public abstract double GetSupportMinValue ();
65+
66+
/**
67+
* <inheritdoc />
68+
*/
5869
public abstract double GetSupportMaxValue ();
5970

60-
//
71+
/**
72+
* <inheritdoc />
73+
*/
6174
public abstract double GetMaxValueOnSupport ();
6275

63-
// We need to know how many data points we have to make computations using all the information we have.
64-
// If the concrete implementation is "analytical", then must return -1.
76+
/**
77+
* <inheritdoc />
78+
*/
6579
public abstract int GetNumberOfDataPoints();
6680

6781
#endregion
@@ -77,6 +91,9 @@ protected ALightSpectrum(AConvertibleColor dataSource=null) : base(dataSource) {
7791

7892
#region AConvertibleColor methods
7993

94+
/**
95+
* <inheritdoc />
96+
*/
8097
public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.Default)
8198
{
8299
// TODO : Check ConversionStrategy
@@ -92,11 +109,17 @@ MFs [0].DoConvolution (this), MFs [1].DoConvolution (this), MFs [2].DoConvolutio
92109
);
93110
}
94111

112+
/**
113+
* <inheritdoc />
114+
*/
95115
public override CIExyY ToCIExyY (ConversionStrategy strategy = ConversionStrategy.Default)
96116
{
97117
return ToCIEXYZ ().ToCIExyY (strategy);
98118
}
99119

120+
/**
121+
* <inheritdoc />
122+
*/
100123
public override SRGB ToSRGB(ConversionStrategy strategy = ConversionStrategy.Default)
101124
{
102125
return ToCIEXYZ ().ToSRGB (strategy);

ColorSharp/src/LightSpectrums/RegularLightSpectrum.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ namespace Litipk.ColorSharp
3636

3737
namespace LightSpectrums
3838
{
39-
public class RegularLightSpectrum : ALightSpectrum
39+
/**
40+
* Class to handle light spectrum samples with equidistant data points
41+
*/
42+
public sealed class RegularLightSpectrum : ALightSpectrum
4043
{
4144
#region properties
4245

0 commit comments

Comments
 (0)