Browse Source

Refactoring color spaces to use a const epsilon.

af/merge-core
Olivia 9 years ago
parent
commit
dfa7ddfbfb
  1. 8
      src/ImageSharp/Colors/Spaces/CieLab.cs
  2. 8
      src/ImageSharp/Colors/Spaces/CieXyz.cs
  3. 10
      src/ImageSharp/Colors/Spaces/Cmyk.cs
  4. 16
      src/ImageSharp/Colors/Spaces/Hsl.cs
  5. 16
      src/ImageSharp/Colors/Spaces/Hsv.cs

8
src/ImageSharp/Colors/Spaces/CieLab.cs

@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces
using System;
using System.ComponentModel;
using System.Numerics;
using Common;
/// <summary>
/// Represents an CIE LAB 1976 color.
@ -20,11 +21,6 @@ namespace ImageSharp.Colors.Spaces
/// </summary>
public static readonly CieLab Empty = default(CieLab);
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.001f;
/// <summary>
/// The backing vector for SIMD support.
/// </summary>
@ -166,7 +162,7 @@ namespace ImageSharp.Colors.Spaces
/// <inheritdoc/>
public bool Equals(CieLab other)
{
return this.AlmostEquals(other, Epsilon);
return this.AlmostEquals(other, Constants.Epsilon);
}
/// <inheritdoc/>

8
src/ImageSharp/Colors/Spaces/CieXyz.cs

@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces
using System;
using System.ComponentModel;
using System.Numerics;
using Common;
/// <summary>
/// Represents an CIE 1931 color
@ -20,11 +21,6 @@ namespace ImageSharp.Colors.Spaces
/// </summary>
public static readonly CieXyz Empty = default(CieXyz);
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.001f;
/// <summary>
/// The backing vector for SIMD support.
/// </summary>
@ -157,7 +153,7 @@ namespace ImageSharp.Colors.Spaces
/// <inheritdoc/>
public bool Equals(CieXyz other)
{
return this.AlmostEquals(other, Epsilon);
return this.AlmostEquals(other, Constants.Epsilon);
}
/// <inheritdoc/>

10
src/ImageSharp/Colors/Spaces/Cmyk.cs

@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces
using System;
using System.ComponentModel;
using System.Numerics;
using Common;
/// <summary>
/// Represents an CMYK (cyan, magenta, yellow, keyline) color.
@ -19,11 +20,6 @@ namespace ImageSharp.Colors.Spaces
/// </summary>
public static readonly Cmyk Empty = default(Cmyk);
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.001f;
/// <summary>
/// The backing vector for SIMD support.
/// </summary>
@ -90,7 +86,7 @@ namespace ImageSharp.Colors.Spaces
float k = Math.Min(c, Math.Min(m, y));
if (Math.Abs(k - 1.0f) <= Epsilon)
if (Math.Abs(k - 1.0f) <= Constants.Epsilon)
{
return new Cmyk(0, 0, 0, 1);
}
@ -167,7 +163,7 @@ namespace ImageSharp.Colors.Spaces
/// <inheritdoc/>
public bool Equals(Cmyk other)
{
return this.AlmostEquals(other, Epsilon);
return this.AlmostEquals(other, Constants.Epsilon);
}
/// <inheritdoc/>

16
src/ImageSharp/Colors/Spaces/Hsl.cs

@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces
using System;
using System.ComponentModel;
using System.Numerics;
using Common;
/// <summary>
/// Represents a Hsl (hue, saturation, lightness) color.
@ -19,11 +20,6 @@ namespace ImageSharp.Colors.Spaces
/// </summary>
public static readonly Hsl Empty = default(Hsl);
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.001F;
/// <summary>
/// The backing vector for SIMD support.
/// </summary>
@ -85,20 +81,20 @@ namespace ImageSharp.Colors.Spaces
float s = 0;
float l = (max + min) / 2;
if (Math.Abs(chroma) < Epsilon)
if (Math.Abs(chroma) < Constants.Epsilon)
{
return new Hsl(0, s, l);
}
if (Math.Abs(r - max) < Epsilon)
if (Math.Abs(r - max) < Constants.Epsilon)
{
h = (g - b) / chroma;
}
else if (Math.Abs(g - max) < Epsilon)
else if (Math.Abs(g - max) < Constants.Epsilon)
{
h = 2 + ((b - r) / chroma);
}
else if (Math.Abs(b - max) < Epsilon)
else if (Math.Abs(b - max) < Constants.Epsilon)
{
h = 4 + ((r - g) / chroma);
}
@ -186,7 +182,7 @@ namespace ImageSharp.Colors.Spaces
/// <inheritdoc/>
public bool Equals(Hsl other)
{
return this.AlmostEquals(other, Epsilon);
return this.AlmostEquals(other, Constants.Epsilon);
}
/// <inheritdoc/>

16
src/ImageSharp/Colors/Spaces/Hsv.cs

@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces
using System;
using System.ComponentModel;
using System.Numerics;
using Common;
/// <summary>
/// Represents a HSV (hue, saturation, value) color. Also known as HSB (hue, saturation, brightness).
@ -19,11 +20,6 @@ namespace ImageSharp.Colors.Spaces
/// </summary>
public static readonly Hsv Empty = default(Hsv);
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.001F;
/// <summary>
/// The backing vector for SIMD support.
/// </summary>
@ -85,20 +81,20 @@ namespace ImageSharp.Colors.Spaces
float s = 0;
float v = max;
if (Math.Abs(chroma) < Epsilon)
if (Math.Abs(chroma) < Constants.Epsilon)
{
return new Hsv(0, s, v);
}
if (Math.Abs(r - max) < Epsilon)
if (Math.Abs(r - max) < Constants.Epsilon)
{
h = (g - b) / chroma;
}
else if (Math.Abs(g - max) < Epsilon)
else if (Math.Abs(g - max) < Constants.Epsilon)
{
h = 2 + ((b - r) / chroma);
}
else if (Math.Abs(b - max) < Epsilon)
else if (Math.Abs(b - max) < Constants.Epsilon)
{
h = 4 + ((r - g) / chroma);
}
@ -179,7 +175,7 @@ namespace ImageSharp.Colors.Spaces
/// <inheritdoc/>
public bool Equals(Hsv other)
{
return this.AlmostEquals(other, Epsilon);
return this.AlmostEquals(other, Constants.Epsilon);
}
/// <inheritdoc/>

Loading…
Cancel
Save