diff --git a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs index df5cec71c..67ff0c308 100644 --- a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs +++ b/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 : ImageFilteringProcessor where TColor : struct, IPackedPixel, IEquatable { - private const float Epsilon = 0.001f; - private const float AntialiasFactor = 1f; private const int DrawPadding = 1; private readonly IBrush 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(); diff --git a/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs index 122c5a0ff..bd5fa1bb2 100644 --- a/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs +++ b/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; /// /// Sets the background color of the image. @@ -16,11 +17,6 @@ namespace ImageSharp.Processors public class BackgroundColorProcessor : ImageFilteringProcessor where TColor : struct, IPackedPixel, IEquatable { - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.001f; - /// /// Initializes a new instance of the class. /// @@ -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; } diff --git a/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs index 33e5b6470..88f7f6c13 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs +++ b/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; /// /// Provides methods that allow the rotating of images. @@ -70,9 +71,7 @@ namespace ImageSharp.Processors /// protected override void BeforeApply(ImageBase 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 /// The private bool OptimizedApply(ImageBase 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; diff --git a/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs b/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs index debc9518b..9471d71db 100644 --- a/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs +++ b/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; /// /// An implementation of Wu's color quantizer with alpha channel. @@ -33,11 +34,6 @@ namespace ImageSharp.Quantizers public sealed class WuQuantizer : IQuantizer where TColor : struct, IPackedPixel, IEquatable { - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 1e-5F; - /// /// The index bits. /// @@ -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);