Browse Source

Refactoring ImageMaths

pull/60/head
Olivia 9 years ago
parent
commit
479084323b
  1. 18
      src/ImageSharp/Common/Helpers/ImageMaths.cs

18
src/ImageSharp/Common/Helpers/ImageMaths.cs

@ -8,6 +8,7 @@ namespace ImageSharp
using System; using System;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Common;
/// <summary> /// <summary>
/// Provides common mathematical methods. /// Provides common mathematical methods.
@ -91,9 +92,7 @@ namespace ImageSharp
/// </returns> /// </returns>
public static float SinC(float x) public static float SinC(float x)
{ {
const float Epsilon = .00001F; if (Math.Abs(x) > Constants.Epsilon)
if (Math.Abs(x) > Epsilon)
{ {
x *= (float)Math.PI; x *= (float)Math.PI;
return Clean((float)Math.Sin(x) / x); return Clean((float)Math.Sin(x) / x);
@ -166,7 +165,6 @@ namespace ImageSharp
public static Rectangle GetFilteredBoundingRectangle<TColor>(ImageBase<TColor> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) public static Rectangle GetFilteredBoundingRectangle<TColor>(ImageBase<TColor> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
const float Epsilon = .00001f;
int width = bitmap.Width; int width = bitmap.Width;
int height = bitmap.Height; int height = bitmap.Height;
Point topLeft = default(Point); Point topLeft = default(Point);
@ -178,19 +176,19 @@ namespace ImageSharp
switch (channel) switch (channel)
{ {
case RgbaComponent.R: case RgbaComponent.R:
delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToVector4().X - b) > Epsilon; delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToVector4().X - b) > Constants.Epsilon;
break; break;
case RgbaComponent.G: case RgbaComponent.G:
delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToVector4().Y - b) > Epsilon; delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToVector4().Y - b) > Constants.Epsilon;
break; break;
case RgbaComponent.B: case RgbaComponent.B:
delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToVector4().Z - b) > Epsilon; delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToVector4().Z - b) > Constants.Epsilon;
break; break;
default: default:
delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToVector4().W - b) > Epsilon; delegateFunc = (pixels, x, y, b) => Math.Abs(pixels[x, y].ToVector4().W - b) > Constants.Epsilon;
break; break;
} }
@ -278,9 +276,7 @@ namespace ImageSharp
/// </returns>. /// </returns>.
private static float Clean(float x) private static float Clean(float x)
{ {
const float Epsilon = .00001F; if (Math.Abs(x) < Constants.Epsilon)
if (Math.Abs(x) < Epsilon)
{ {
return 0F; return 0F;
} }

Loading…
Cancel
Save