Browse Source

Refactoring the rest to use a const epsilon.

af/merge-core
Olivia 9 years ago
parent
commit
61b7d3aedb
  1. 5
      src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs
  2. 8
      src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs
  3. 14
      src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs
  4. 12
      src/ImageSharp/Quantizers/Wu/WuQuantizer.cs

5
src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs

@ -8,6 +8,7 @@ namespace ImageSharp.Drawing.Processors
using System;
using System.Numerics;
using System.Threading.Tasks;
using Common;
using Drawing;
using ImageSharp.Processors;
using Shapes;
@ -21,8 +22,6 @@ namespace ImageSharp.Drawing.Processors
public class FillShapeProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private const float Epsilon = 0.001f;
private const float AntialiasFactor = 1f;
private const int DrawPadding = 1;
private readonly IBrush<TColor> fillColor;
@ -95,7 +94,7 @@ namespace ImageSharp.Drawing.Processors
float dist = this.poly.Distance(currentPoint);
float opacity = this.Opacity(dist);
if (opacity > Epsilon)
if (opacity > Constants.Epsilon)
{
Vector4 backgroundVector = sourcePixels[offsetX, offsetY].ToVector4();
Vector4 sourceVector = applicator.GetColor(currentPoint).ToVector4();

8
src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs

@ -8,6 +8,7 @@ namespace ImageSharp.Processors
using System;
using System.Numerics;
using System.Threading.Tasks;
using Common;
/// <summary>
/// Sets the background color of the image.
@ -16,11 +17,6 @@ namespace ImageSharp.Processors
public class BackgroundColorProcessor<TColor> : ImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 0.001f;
/// <summary>
/// Initializes a new instance of the <see cref="BackgroundColorProcessor{TColor}"/> class.
/// </summary>
@ -82,7 +78,7 @@ namespace ImageSharp.Processors
color = Vector4BlendTransforms.PremultipliedLerp(backgroundColor, color, .5F);
}
if (Math.Abs(a) < Epsilon)
if (Math.Abs(a) < Constants.Epsilon)
{
color = backgroundColor;
}

14
src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs

@ -8,6 +8,7 @@ namespace ImageSharp.Processors
using System;
using System.Numerics;
using System.Threading.Tasks;
using Common;
/// <summary>
/// Provides methods that allow the rotating of images.
@ -70,9 +71,7 @@ namespace ImageSharp.Processors
/// <inheritdoc/>
protected override void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
const float Epsilon = .0001F;
if (Math.Abs(this.Angle) < Epsilon || Math.Abs(this.Angle - 90) < Epsilon || Math.Abs(this.Angle - 180) < Epsilon || Math.Abs(this.Angle - 270) < Epsilon)
if (Math.Abs(this.Angle) < Constants.Epsilon || Math.Abs(this.Angle - 90) < Constants.Epsilon || Math.Abs(this.Angle - 180) < Constants.Epsilon || Math.Abs(this.Angle - 270) < Constants.Epsilon)
{
return;
}
@ -91,26 +90,25 @@ namespace ImageSharp.Processors
/// <returns>The <see cref="bool"/></returns>
private bool OptimizedApply(ImageBase<TColor> source)
{
const float Epsilon = .0001F;
if (Math.Abs(this.Angle) < Epsilon)
if (Math.Abs(this.Angle) < Constants.Epsilon)
{
// No need to do anything so return.
return true;
}
if (Math.Abs(this.Angle - 90) < Epsilon)
if (Math.Abs(this.Angle - 90) < Constants.Epsilon)
{
this.Rotate90(source);
return true;
}
if (Math.Abs(this.Angle - 180) < Epsilon)
if (Math.Abs(this.Angle - 180) < Constants.Epsilon)
{
this.Rotate180(source);
return true;
}
if (Math.Abs(this.Angle - 270) < Epsilon)
if (Math.Abs(this.Angle - 270) < Constants.Epsilon)
{
this.Rotate270(source);
return true;

12
src/ImageSharp/Quantizers/Wu/WuQuantizer.cs

@ -9,6 +9,7 @@ namespace ImageSharp.Quantizers
using System.Buffers;
using System.Numerics;
using System.Threading.Tasks;
using Common;
/// <summary>
/// An implementation of Wu's color quantizer with alpha channel.
@ -33,11 +34,6 @@ namespace ImageSharp.Quantizers
public sealed class WuQuantizer<TColor> : IQuantizer<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// The epsilon for comparing floating point numbers.
/// </summary>
private const float Epsilon = 1e-5F;
/// <summary>
/// The index bits.
/// </summary>
@ -542,7 +538,7 @@ namespace ImageSharp.Quantizers
double temp;
if (Math.Abs(halfW) < Epsilon)
if (Math.Abs(halfW) < Constants.Epsilon)
{
continue;
}
@ -555,7 +551,7 @@ namespace ImageSharp.Quantizers
halfA = wholeA - halfA;
halfW = wholeW - halfW;
if (Math.Abs(halfW) < Epsilon)
if (Math.Abs(halfW) < Constants.Epsilon)
{
continue;
}
@ -762,7 +758,7 @@ namespace ImageSharp.Quantizers
double weight = Volume(cube[k], this.vwt);
if (Math.Abs(weight) > Epsilon)
if (Math.Abs(weight) > Constants.Epsilon)
{
float r = (float)(Volume(cube[k], this.vmr) / weight);
float g = (float)(Volume(cube[k], this.vmg) / weight);

Loading…
Cancel
Save