Browse Source

Refactoring ColorspaceTransforms to use a const epsilon.

af/merge-core
Olivia 10 years ago
parent
commit
84595c0d71
  1. 14
      src/ImageSharp/Colors/ColorspaceTransforms.cs

14
src/ImageSharp/Colors/ColorspaceTransforms.cs

@ -8,6 +8,7 @@ namespace ImageSharp
using System; using System;
using System.Numerics; using System.Numerics;
using Colors.Spaces; using Colors.Spaces;
using Common;
/// <summary> /// <summary>
/// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255. /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255.
@ -19,11 +20,6 @@ namespace ImageSharp
/// </remarks> /// </remarks>
public partial struct Color public partial struct Color
{ {
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.001F;
/// <summary> /// <summary>
/// Allows the implicit conversion of an instance of <see cref="Color"/> to a /// Allows the implicit conversion of an instance of <see cref="Color"/> to a
/// <see cref="Bgra32"/>. /// <see cref="Bgra32"/>.
@ -110,12 +106,12 @@ namespace ImageSharp
float s = color.S; float s = color.S;
float v = color.V; float v = color.V;
if (Math.Abs(s) < Epsilon) if (Math.Abs(s) < Constants.Epsilon)
{ {
return new Color(v, v, v, 1); return new Color(v, v, v, 1);
} }
float h = (Math.Abs(color.H - 360) < Epsilon) ? 0 : color.H / 60; float h = (Math.Abs(color.H - 360) < Constants.Epsilon) ? 0 : color.H / 60;
int i = (int)Math.Truncate(h); int i = (int)Math.Truncate(h);
float f = h - i; float f = h - i;
@ -183,9 +179,9 @@ namespace ImageSharp
float s = color.S; float s = color.S;
float l = color.L; float l = color.L;
if (Math.Abs(l) > Epsilon) if (Math.Abs(l) > Constants.Epsilon)
{ {
if (Math.Abs(s) < Epsilon) if (Math.Abs(s) < Constants.Epsilon)
{ {
r = g = b = l; r = g = b = l;
} }

Loading…
Cancel
Save