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

Commit 707bd34

Browse files
committed
Added HashCode methods to light spectrum objects
1 parent 6f2d746 commit 707bd34

File tree

13 files changed

+128
-54
lines changed

13 files changed

+128
-54
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
ColorSharp's Changelog
22
======================
33

4+
## 2014-12-19 : 0.8.3 Release
5+
6+
### Contributors
7+
* Andrés Correa Casablanca <castarco@gmail.com , castarco@litipk.com>
8+
9+
### Changes
10+
* Updated MathNet.Numerics dependency
11+
* Added HashCode to light spectrum objects
12+
* Minor performance tweaks
13+
14+
415
## 2014-12-05 : 0.8.2 Release
516

617
### Contributors
718
* Andrés Correa Casablanca <castarco@gmail.com , castarco@litipk.com>
819

9-
## Minor changes
20+
### Minor changes
1021
* Added new constructor to the RegularLightSpectrum class.
1122

1223
## 2014-11-12 : 0.8.1 Release

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.8.2
37+
version = 0.8.3
3838
EndGlobalSection
3939
EndGlobal

ColorSharp/ColorSharp.csproj

Lines changed: 4 additions & 4 deletions
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.8.2</ReleaseVersion>
14+
<ReleaseVersion>0.8.3</ReleaseVersion>
1515
</PropertyGroup>
1616
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1717
<DebugSymbols>true</DebugSymbols>
@@ -42,10 +42,10 @@
4242
</PropertyGroup>
4343
<ItemGroup>
4444
<Reference Include="System" />
45+
<Reference Include="System.Numerics" />
4546
<Reference Include="MathNet.Numerics">
46-
<HintPath>..\packages\MathNet.Numerics.Signed.3.2.3\lib\net40\MathNet.Numerics.dll</HintPath>
47+
<HintPath>..\packages\MathNet.Numerics.Signed.3.3.0\lib\net40\MathNet.Numerics.dll</HintPath>
4748
</Reference>
48-
<Reference Include="System.Numerics" />
4949
</ItemGroup>
5050
<ItemGroup>
5151
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -81,9 +81,9 @@
8181
<Folder Include="src\Illuminants\" />
8282
</ItemGroup>
8383
<ItemGroup>
84-
<None Include="packages.config" />
8584
<None Include="ColorSharp.nuspec" />
8685
<None Include="build_nuget_pkg.sh" />
8786
<None Include="colorsharp.pub" />
87+
<None Include="packages.config" />
8888
</ItemGroup>
8989
</Project>

ColorSharp/ColorSharp.nuspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>$description$</description>
1313
<releaseNotes>
14-
- Bugfix in the D65 Illuminant (spectrum sample)
14+
- Updated MathNet.Numerics dependency
15+
- Added HashCode to light spectrum objects
16+
- Minor performance tweaks
1517
</releaseNotes>
1618
<copyright>Copyright 2014</copyright>
1719
<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.8.2.*")]
49+
[assembly: AssemblyVersion ("0.8.3.*")]
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/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="MathNet.Numerics.Signed" version="3.2.3" targetFramework="net40" />
3+
<package id="MathNet.Numerics.Signed" version="3.3.0" targetFramework="net40" />
44
</packages>

ColorSharp/src/ColorSpaces/CIEXYZ.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,26 @@ public override bool Equals(Object obj)
164164
{
165165
CIEXYZ xyzObj = obj as CIEXYZ;
166166

167-
if (xyzObj == null || GetHashCode () != obj.GetHashCode ())
167+
if (xyzObj == this) {
168+
return true;
169+
}
170+
if (xyzObj == null || GetHashCode () != obj.GetHashCode ()) {
168171
return false;
172+
}
169173

170-
return (
171-
Math.Abs (X - xyzObj.X) <= double.Epsilon &&
172-
Math.Abs (Y - xyzObj.Y) <= double.Epsilon &&
173-
Math.Abs (Z - xyzObj.Z) <= double.Epsilon
174-
);
174+
return (X == xyzObj.X && Y == xyzObj.Y && Z == xyzObj.Z);
175175
}
176176

177177
/**
178178
* <inheritdoc />
179179
*/
180180
public override int GetHashCode ()
181181
{
182-
int hash = 23;
182+
int hash = 30967 + X.GetHashCode (); // 30967 == 173 * 179
183183

184-
hash = hash * 57 + X.GetHashCode ();
185-
hash = hash * 57 + Y.GetHashCode ();
186-
hash = hash * 57 + Z.GetHashCode ();
184+
hash = hash * 179 + Y.GetHashCode ();
187185

188-
return hash;
186+
return hash * 179 + Z.GetHashCode ();
189187
}
190188

191189
#endregion

ColorSharp/src/ColorSpaces/CIExyY.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,28 +196,26 @@ public override bool Equals(Object obj)
196196
{
197197
CIExyY xyYObj = obj as CIExyY;
198198

199-
if (xyYObj == null || GetHashCode () != obj.GetHashCode ())
199+
if (xyYObj == this) {
200+
return true;
201+
}
202+
if (xyYObj == null || GetHashCode () != obj.GetHashCode ()) {
200203
return false;
204+
}
201205

202-
return (
203-
Math.Abs (x - xyYObj.x) <= double.Epsilon &&
204-
Math.Abs (y - xyYObj.y) <= double.Epsilon &&
205-
Math.Abs (Y - xyYObj.Y) <= double.Epsilon
206-
);
206+
return (x == xyYObj.x && y == xyYObj.y && Y == xyYObj.Y);
207207
}
208208

209209
/**
210210
* <inheritdoc />
211211
*/
212212
public override int GetHashCode ()
213213
{
214-
int hash = 19;
214+
int hash = 28891 + x.GetHashCode (); // 28891 == 167 * 173
215215

216-
hash = hash * 31 + x.GetHashCode ();
217-
hash = hash * 31 + y.GetHashCode ();
218-
hash = hash * 31 + Y.GetHashCode ();
216+
hash = hash * 173 + y.GetHashCode ();
219217

220-
return hash;
218+
return hash * 173 + Y.GetHashCode ();
221219
}
222220

223221
#endregion

ColorSharp/src/ColorSpaces/SRGB.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,28 +140,26 @@ public override bool Equals(Object obj)
140140
{
141141
SRGB srgbObj = obj as SRGB;
142142

143-
if (srgbObj == null || GetHashCode () != obj.GetHashCode ())
143+
if (srgbObj == this) {
144+
return true;
145+
}
146+
if (srgbObj == null || GetHashCode () != obj.GetHashCode ()) {
144147
return false;
148+
}
145149

146-
return (
147-
Math.Abs (R - srgbObj.R) <= double.Epsilon &&
148-
Math.Abs (G - srgbObj.G) <= double.Epsilon &&
149-
Math.Abs (B - srgbObj.B) <= double.Epsilon
150-
);
150+
return (R == srgbObj.R && G == srgbObj.G && B == srgbObj.B);
151151
}
152152

153153
/**
154154
* <inheritdoc />
155155
*/
156156
public override int GetHashCode ()
157157
{
158-
int hash = 17;
158+
int hash = 32399 + R.GetHashCode (); // 32399 == 179 * 181
159159

160-
hash = hash * 19 + R.GetHashCode ();
161-
hash = hash * 19 + G.GetHashCode ();
162-
hash = hash * 19 + B.GetHashCode ();
160+
hash = hash * 181 + G.GetHashCode ();
163161

164-
return hash;
162+
return hash * 181 + B.GetHashCode ();
165163
}
166164

167165
#endregion

ColorSharp/src/LightSpectrums/ALightSpectrum.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@
2727
*/
2828

2929

30-
using System;
31-
using System.Collections.Generic;
30+
using Litipk.ColorSharp.ColorSpaces;
31+
using Litipk.ColorSharp.MatchingFunctions;
32+
using Litipk.ColorSharp.InternalUtils;
3233

3334

3435
namespace Litipk.ColorSharp
3536
{
36-
using ColorSpaces;
37-
using MatchingFunctions;
38-
using InternalUtils;
39-
4037
namespace LightSpectrums
4138
{
4239
/**

0 commit comments

Comments
 (0)