From 65c848af7bf5162ab207ec2cda5b6ca8e5674ab9 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 12:55:01 +0200 Subject: [PATCH 01/11] Adding CommonConstants. --- src/ImageSharp/Common/CommonConstants.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/ImageSharp/Common/CommonConstants.cs diff --git a/src/ImageSharp/Common/CommonConstants.cs b/src/ImageSharp/Common/CommonConstants.cs new file mode 100644 index 0000000000..4bae66debe --- /dev/null +++ b/src/ImageSharp/Common/CommonConstants.cs @@ -0,0 +1,18 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Common +{ + /// + /// Common constants used throughout the project + /// + public static class CommonConstants + { + /// + /// The epsilon for comparing floating point numbers. + /// + public static readonly float Epsilon = 0.001f; + } +} From e2eb4901bb61555e1e742ff2e160faaea22d5ba8 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 12:55:55 +0200 Subject: [PATCH 02/11] Renaming to Constants --- src/ImageSharp/Common/{CommonConstants.cs => Constants.cs} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/ImageSharp/Common/{CommonConstants.cs => Constants.cs} (78%) diff --git a/src/ImageSharp/Common/CommonConstants.cs b/src/ImageSharp/Common/Constants.cs similarity index 78% rename from src/ImageSharp/Common/CommonConstants.cs rename to src/ImageSharp/Common/Constants.cs index 4bae66debe..308811a42b 100644 --- a/src/ImageSharp/Common/CommonConstants.cs +++ b/src/ImageSharp/Common/Constants.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -8,7 +8,7 @@ namespace ImageSharp.Common /// /// Common constants used throughout the project /// - public static class CommonConstants + public static class Constants { /// /// The epsilon for comparing floating point numbers. From dfa7ddfbfb61ef8b0483962a4f6e709b7f18a8a8 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 13:04:32 +0200 Subject: [PATCH 03/11] Refactoring color spaces to use a const epsilon. --- src/ImageSharp/Colors/Spaces/CieLab.cs | 8 ++------ src/ImageSharp/Colors/Spaces/CieXyz.cs | 8 ++------ src/ImageSharp/Colors/Spaces/Cmyk.cs | 10 +++------- src/ImageSharp/Colors/Spaces/Hsl.cs | 16 ++++++---------- src/ImageSharp/Colors/Spaces/Hsv.cs | 16 ++++++---------- 5 files changed, 19 insertions(+), 39 deletions(-) diff --git a/src/ImageSharp/Colors/Spaces/CieLab.cs b/src/ImageSharp/Colors/Spaces/CieLab.cs index faa6c24724..dd72a966fe 100644 --- a/src/ImageSharp/Colors/Spaces/CieLab.cs +++ b/src/ImageSharp/Colors/Spaces/CieLab.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using Common; /// /// Represents an CIE LAB 1976 color. @@ -20,11 +21,6 @@ namespace ImageSharp.Colors.Spaces /// public static readonly CieLab Empty = default(CieLab); - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.001f; - /// /// The backing vector for SIMD support. /// @@ -166,7 +162,7 @@ namespace ImageSharp.Colors.Spaces /// public bool Equals(CieLab other) { - return this.AlmostEquals(other, Epsilon); + return this.AlmostEquals(other, Constants.Epsilon); } /// diff --git a/src/ImageSharp/Colors/Spaces/CieXyz.cs b/src/ImageSharp/Colors/Spaces/CieXyz.cs index 9deffe0669..33b763f2be 100644 --- a/src/ImageSharp/Colors/Spaces/CieXyz.cs +++ b/src/ImageSharp/Colors/Spaces/CieXyz.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using Common; /// /// Represents an CIE 1931 color @@ -20,11 +21,6 @@ namespace ImageSharp.Colors.Spaces /// public static readonly CieXyz Empty = default(CieXyz); - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.001f; - /// /// The backing vector for SIMD support. /// @@ -157,7 +153,7 @@ namespace ImageSharp.Colors.Spaces /// public bool Equals(CieXyz other) { - return this.AlmostEquals(other, Epsilon); + return this.AlmostEquals(other, Constants.Epsilon); } /// diff --git a/src/ImageSharp/Colors/Spaces/Cmyk.cs b/src/ImageSharp/Colors/Spaces/Cmyk.cs index e8f2a41f5c..41e88ca8f2 100644 --- a/src/ImageSharp/Colors/Spaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Spaces/Cmyk.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using Common; /// /// Represents an CMYK (cyan, magenta, yellow, keyline) color. @@ -19,11 +20,6 @@ namespace ImageSharp.Colors.Spaces /// public static readonly Cmyk Empty = default(Cmyk); - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.001f; - /// /// The backing vector for SIMD support. /// @@ -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 /// public bool Equals(Cmyk other) { - return this.AlmostEquals(other, Epsilon); + return this.AlmostEquals(other, Constants.Epsilon); } /// diff --git a/src/ImageSharp/Colors/Spaces/Hsl.cs b/src/ImageSharp/Colors/Spaces/Hsl.cs index 5c478ecf14..a57c15981b 100644 --- a/src/ImageSharp/Colors/Spaces/Hsl.cs +++ b/src/ImageSharp/Colors/Spaces/Hsl.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using Common; /// /// Represents a Hsl (hue, saturation, lightness) color. @@ -19,11 +20,6 @@ namespace ImageSharp.Colors.Spaces /// public static readonly Hsl Empty = default(Hsl); - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.001F; - /// /// The backing vector for SIMD support. /// @@ -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 /// public bool Equals(Hsl other) { - return this.AlmostEquals(other, Epsilon); + return this.AlmostEquals(other, Constants.Epsilon); } /// diff --git a/src/ImageSharp/Colors/Spaces/Hsv.cs b/src/ImageSharp/Colors/Spaces/Hsv.cs index 9df16a27b4..28c1e12598 100644 --- a/src/ImageSharp/Colors/Spaces/Hsv.cs +++ b/src/ImageSharp/Colors/Spaces/Hsv.cs @@ -8,6 +8,7 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; + using Common; /// /// Represents a HSV (hue, saturation, value) color. Also known as HSB (hue, saturation, brightness). @@ -19,11 +20,6 @@ namespace ImageSharp.Colors.Spaces /// public static readonly Hsv Empty = default(Hsv); - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.001F; - /// /// The backing vector for SIMD support. /// @@ -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 /// public bool Equals(Hsv other) { - return this.AlmostEquals(other, Epsilon); + return this.AlmostEquals(other, Constants.Epsilon); } /// From 84595c0d715fde33dff25f3c9ba64430a63301f0 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 13:07:02 +0200 Subject: [PATCH 04/11] Refactoring ColorspaceTransforms to use a const epsilon. --- src/ImageSharp/Colors/ColorspaceTransforms.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index 9785a888f4..578f10e29f 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -8,6 +8,7 @@ namespace ImageSharp using System; using System.Numerics; using Colors.Spaces; + using Common; /// /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255. @@ -19,11 +20,6 @@ namespace ImageSharp /// public partial struct Color { - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.001F; - /// /// Allows the implicit conversion of an instance of to a /// . @@ -110,12 +106,12 @@ namespace ImageSharp float s = color.S; float v = color.V; - if (Math.Abs(s) < Epsilon) + if (Math.Abs(s) < Constants.Epsilon) { 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); float f = h - i; @@ -183,9 +179,9 @@ namespace ImageSharp float s = color.S; 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; } From 123022e7b56d3d1647c4beea7bcedd4d3687014e Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 13:12:05 +0200 Subject: [PATCH 05/11] Adding a test to protect the epsilon value. --- .../ImageSharp.Tests/Common/ConstantsTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/ImageSharp.Tests/Common/ConstantsTests.cs diff --git a/tests/ImageSharp.Tests/Common/ConstantsTests.cs b/tests/ImageSharp.Tests/Common/ConstantsTests.cs new file mode 100644 index 0000000000..d1ca6cd02c --- /dev/null +++ b/tests/ImageSharp.Tests/Common/ConstantsTests.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Common +{ + using ImageSharp.Common; + using Xunit; + + public class ConstantsTests + { + [Fact] + public void Epsilon() + { + Assert.Equal(Constants.Epsilon, 0.001f); + } + } +} From 81a3f2e2c3ba1d2cb047e27882b0d7d2dc576482 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 13:29:06 +0200 Subject: [PATCH 06/11] Making constants internal. --- src/ImageSharp/Common/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageSharp/Common/Constants.cs b/src/ImageSharp/Common/Constants.cs index 308811a42b..1db4bc9656 100644 --- a/src/ImageSharp/Common/Constants.cs +++ b/src/ImageSharp/Common/Constants.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Common /// /// Common constants used throughout the project /// - public static class Constants + internal static class Constants { /// /// The epsilon for comparing floating point numbers. From d47bde153f2def0e92e81d0dea59240df4908e66 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 13:50:16 +0200 Subject: [PATCH 07/11] Refactoring Vector4BlendTransforms to use a const epsilon. --- src/ImageSharp/Colors/Vector4BlendTransforms.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp/Colors/Vector4BlendTransforms.cs b/src/ImageSharp/Colors/Vector4BlendTransforms.cs index 870d653888..ad69f7bcbe 100644 --- a/src/ImageSharp/Colors/Vector4BlendTransforms.cs +++ b/src/ImageSharp/Colors/Vector4BlendTransforms.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using Common; /// /// Transform algorithms that match the equations defined in the W3C Compositing and Blending Level 1 specification. @@ -14,11 +15,6 @@ namespace ImageSharp /// public class Vector4BlendTransforms { - /// - /// The epsilon for comparing floating point numbers. - /// - private const float Epsilon = 0.0001F; - /// /// The blending formula simply selects the source vector. /// @@ -203,13 +199,13 @@ namespace ImageSharp amount = amount.Clamp(0, 1); // Santize on zero alpha - if (Math.Abs(backdrop.W) < Epsilon) + if (Math.Abs(backdrop.W) < Constants.Epsilon) { source.W *= amount; return source; } - if (Math.Abs(source.W) < Epsilon) + if (Math.Abs(source.W) < Constants.Epsilon) { return backdrop; } @@ -266,7 +262,7 @@ namespace ImageSharp /// private static float BlendDodge(float b, float s) { - return Math.Abs(s - 1F) < Epsilon ? s : Math.Min(b / (1F - s), 1F); + return Math.Abs(s - 1F) < Constants.Epsilon ? s : Math.Min(b / (1F - s), 1F); } /// @@ -279,7 +275,7 @@ namespace ImageSharp /// private static float BlendBurn(float b, float s) { - return Math.Abs(s) < Epsilon ? s : Math.Max(1F - ((1F - b) / s), 0F); + return Math.Abs(s) < Constants.Epsilon ? s : Math.Max(1F - ((1F - b) / s), 0F); } /// From 6890a7f3adb7276e4a540cded1d4109783fd9280 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 13:58:09 +0200 Subject: [PATCH 08/11] Refactoring ImageMaths --- src/ImageSharp/Common/Helpers/ImageMaths.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs index 99212346aa..c62a97b03c 100644 --- a/src/ImageSharp/Common/Helpers/ImageMaths.cs +++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs @@ -8,6 +8,7 @@ namespace ImageSharp using System; using System.Linq; using System.Numerics; + using Common; /// /// Provides common mathematical methods. @@ -91,9 +92,7 @@ namespace ImageSharp /// public static float SinC(float x) { - const float Epsilon = .00001F; - - if (Math.Abs(x) > Epsilon) + if (Math.Abs(x) > Constants.Epsilon) { x *= (float)Math.PI; return Clean((float)Math.Sin(x) / x); @@ -166,7 +165,6 @@ namespace ImageSharp public static Rectangle GetFilteredBoundingRectangle(ImageBase bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B) where TColor : struct, IPackedPixel, IEquatable { - const float Epsilon = .00001f; int width = bitmap.Width; int height = bitmap.Height; Point topLeft = default(Point); @@ -178,19 +176,19 @@ namespace ImageSharp switch (channel) { 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; 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; 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; 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; } @@ -278,9 +276,7 @@ namespace ImageSharp /// . private static float Clean(float x) { - const float Epsilon = .00001F; - - if (Math.Abs(x) < Epsilon) + if (Math.Abs(x) < Constants.Epsilon) { return 0F; } From a135515ff412637f649b36b80b68d409fb6f8804 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 14:02:51 +0200 Subject: [PATCH 09/11] Refactoring DrawPathProcessor to use a const epsilon. --- src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs b/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs index 54ebc28efd..8cbee79085 100644 --- a/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs @@ -9,7 +9,7 @@ namespace ImageSharp.Drawing.Processors using System.Linq; using System.Numerics; using System.Threading.Tasks; - + using Common; using ImageSharp.Processors; using Paths; using Pens; @@ -27,7 +27,6 @@ namespace ImageSharp.Drawing.Processors { private const float AntialiasFactor = 1f; private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor - private const float Epsilon = 0.001f; private readonly IPen pen; private readonly IPath[] paths; @@ -138,7 +137,7 @@ namespace ImageSharp.Drawing.Processors var opacity = this.Opacity(color.DistanceFromElement); - if (opacity > Epsilon) + if (opacity > Constants.Epsilon) { int offsetColorX = x - minX; From 61b7d3aedba3b9d6a64e42e894e45e5a0dd738e6 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 14:07:13 +0200 Subject: [PATCH 10/11] Refactoring the rest to use a const epsilon. --- .../Drawing/Processors/FillShapeProcessor.cs | 5 ++--- .../Processors/Effects/BackgroundColorProcessor.cs | 8 ++------ .../Processors/Transforms/RotateProcessor.cs | 14 ++++++-------- src/ImageSharp/Quantizers/Wu/WuQuantizer.cs | 12 ++++-------- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs index df5cec71c8..67ff0c3083 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 122c5a0ffe..bd5fa1bb20 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 33e5b64707..88f7f6c136 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 debc9518be..9471d71db4 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); From 8d689c9f2cf51c01cc03a58fd3275c67874e8460 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 28 Dec 2016 18:36:20 +0200 Subject: [PATCH 11/11] Removing common namespace. --- src/ImageSharp/Colors/ColorspaceTransforms.cs | 1 - src/ImageSharp/Colors/Spaces/CieLab.cs | 1 - src/ImageSharp/Colors/Spaces/CieXyz.cs | 1 - src/ImageSharp/Colors/Spaces/Cmyk.cs | 1 - src/ImageSharp/Colors/Spaces/Hsl.cs | 1 - src/ImageSharp/Colors/Spaces/Hsv.cs | 1 - src/ImageSharp/Colors/Vector4BlendTransforms.cs | 1 - src/ImageSharp/Common/Constants.cs | 2 +- src/ImageSharp/Common/Helpers/ImageMaths.cs | 1 - src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs | 1 - src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs | 1 - .../Filters/Processors/Effects/BackgroundColorProcessor.cs | 1 - src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs | 1 - src/ImageSharp/Quantizers/Wu/WuQuantizer.cs | 1 - tests/ImageSharp.Tests/Common/ConstantsTests.cs | 1 - 15 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/ImageSharp/Colors/ColorspaceTransforms.cs b/src/ImageSharp/Colors/ColorspaceTransforms.cs index 578f10e29f..cda7022705 100644 --- a/src/ImageSharp/Colors/ColorspaceTransforms.cs +++ b/src/ImageSharp/Colors/ColorspaceTransforms.cs @@ -8,7 +8,6 @@ namespace ImageSharp using System; using System.Numerics; using Colors.Spaces; - using Common; /// /// Packed vector type containing four 8-bit unsigned normalized values ranging from 0 to 255. diff --git a/src/ImageSharp/Colors/Spaces/CieLab.cs b/src/ImageSharp/Colors/Spaces/CieLab.cs index dd72a966fe..f4f349b52b 100644 --- a/src/ImageSharp/Colors/Spaces/CieLab.cs +++ b/src/ImageSharp/Colors/Spaces/CieLab.cs @@ -8,7 +8,6 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; - using Common; /// /// Represents an CIE LAB 1976 color. diff --git a/src/ImageSharp/Colors/Spaces/CieXyz.cs b/src/ImageSharp/Colors/Spaces/CieXyz.cs index 33b763f2be..49396d3f61 100644 --- a/src/ImageSharp/Colors/Spaces/CieXyz.cs +++ b/src/ImageSharp/Colors/Spaces/CieXyz.cs @@ -8,7 +8,6 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; - using Common; /// /// Represents an CIE 1931 color diff --git a/src/ImageSharp/Colors/Spaces/Cmyk.cs b/src/ImageSharp/Colors/Spaces/Cmyk.cs index 41e88ca8f2..190d73598f 100644 --- a/src/ImageSharp/Colors/Spaces/Cmyk.cs +++ b/src/ImageSharp/Colors/Spaces/Cmyk.cs @@ -8,7 +8,6 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; - using Common; /// /// Represents an CMYK (cyan, magenta, yellow, keyline) color. diff --git a/src/ImageSharp/Colors/Spaces/Hsl.cs b/src/ImageSharp/Colors/Spaces/Hsl.cs index a57c15981b..2cb02107b9 100644 --- a/src/ImageSharp/Colors/Spaces/Hsl.cs +++ b/src/ImageSharp/Colors/Spaces/Hsl.cs @@ -8,7 +8,6 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; - using Common; /// /// Represents a Hsl (hue, saturation, lightness) color. diff --git a/src/ImageSharp/Colors/Spaces/Hsv.cs b/src/ImageSharp/Colors/Spaces/Hsv.cs index 28c1e12598..8f7ebbdc76 100644 --- a/src/ImageSharp/Colors/Spaces/Hsv.cs +++ b/src/ImageSharp/Colors/Spaces/Hsv.cs @@ -8,7 +8,6 @@ namespace ImageSharp.Colors.Spaces using System; using System.ComponentModel; using System.Numerics; - using Common; /// /// Represents a HSV (hue, saturation, value) color. Also known as HSB (hue, saturation, brightness). diff --git a/src/ImageSharp/Colors/Vector4BlendTransforms.cs b/src/ImageSharp/Colors/Vector4BlendTransforms.cs index ad69f7bcbe..2fa6aad4b4 100644 --- a/src/ImageSharp/Colors/Vector4BlendTransforms.cs +++ b/src/ImageSharp/Colors/Vector4BlendTransforms.cs @@ -7,7 +7,6 @@ namespace ImageSharp { using System; using System.Numerics; - using Common; /// /// Transform algorithms that match the equations defined in the W3C Compositing and Blending Level 1 specification. diff --git a/src/ImageSharp/Common/Constants.cs b/src/ImageSharp/Common/Constants.cs index 1db4bc9656..cf43951bc5 100644 --- a/src/ImageSharp/Common/Constants.cs +++ b/src/ImageSharp/Common/Constants.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Common +namespace ImageSharp { /// /// Common constants used throughout the project diff --git a/src/ImageSharp/Common/Helpers/ImageMaths.cs b/src/ImageSharp/Common/Helpers/ImageMaths.cs index c62a97b03c..7455b542d1 100644 --- a/src/ImageSharp/Common/Helpers/ImageMaths.cs +++ b/src/ImageSharp/Common/Helpers/ImageMaths.cs @@ -8,7 +8,6 @@ namespace ImageSharp using System; using System.Linq; using System.Numerics; - using Common; /// /// Provides common mathematical methods. diff --git a/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs b/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs index 8cbee79085..dab0baa5a2 100644 --- a/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs @@ -9,7 +9,6 @@ namespace ImageSharp.Drawing.Processors using System.Linq; using System.Numerics; using System.Threading.Tasks; - using Common; using ImageSharp.Processors; using Paths; using Pens; diff --git a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs index 67ff0c3083..7da2e041a2 100644 --- a/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs +++ b/src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs @@ -8,7 +8,6 @@ namespace ImageSharp.Drawing.Processors using System; using System.Numerics; using System.Threading.Tasks; - using Common; using Drawing; using ImageSharp.Processors; using Shapes; diff --git a/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs index bd5fa1bb20..ab6fa2424f 100644 --- a/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs @@ -8,7 +8,6 @@ namespace ImageSharp.Processors using System; using System.Numerics; using System.Threading.Tasks; - using Common; /// /// Sets the background color of the image. diff --git a/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs index 88f7f6c136..e81cd7e57e 100644 --- a/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Filters/Processors/Transforms/RotateProcessor.cs @@ -8,7 +8,6 @@ namespace ImageSharp.Processors using System; using System.Numerics; using System.Threading.Tasks; - using Common; /// /// Provides methods that allow the rotating of images. diff --git a/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs b/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs index 9471d71db4..e235e68e88 100644 --- a/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs +++ b/src/ImageSharp/Quantizers/Wu/WuQuantizer.cs @@ -9,7 +9,6 @@ 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. diff --git a/tests/ImageSharp.Tests/Common/ConstantsTests.cs b/tests/ImageSharp.Tests/Common/ConstantsTests.cs index d1ca6cd02c..0adda0c0f6 100644 --- a/tests/ImageSharp.Tests/Common/ConstantsTests.cs +++ b/tests/ImageSharp.Tests/Common/ConstantsTests.cs @@ -5,7 +5,6 @@ namespace ImageSharp.Tests.Common { - using ImageSharp.Common; using Xunit; public class ConstantsTests