From a16d51894594a59f7bd1ea2ed76b66a8447c96b5 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:31:08 -0700 Subject: [PATCH 01/28] [SL.Core] Cross target .NETCOREAPP2.1 --- src/SixLabors.Core/MathF.cs | 2 +- src/SixLabors.Core/SixLabors.Core.csproj | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/SixLabors.Core/MathF.cs b/src/SixLabors.Core/MathF.cs index 3079c9100..1329dbdae 100644 --- a/src/SixLabors.Core/MathF.cs +++ b/src/SixLabors.Core/MathF.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; -#if NETCOREAPP2_0 +#if NETCOREAPP2_0 || NETCOREAPP2_1 [assembly: TypeForwardedTo(typeof(System.MathF))] #else namespace System diff --git a/src/SixLabors.Core/SixLabors.Core.csproj b/src/SixLabors.Core/SixLabors.Core.csproj index bc37cd2e2..65955529d 100644 --- a/src/SixLabors.Core/SixLabors.Core.csproj +++ b/src/SixLabors.Core/SixLabors.Core.csproj @@ -5,7 +5,7 @@ $(packageversion) 0.1.0-alpha2 Six Labors - netstandard1.1;netcoreapp2.0; + netstandard1.1;netcoreapp2.0;netcoreapp2.1; true true SixLabors.Core @@ -39,13 +39,18 @@ - - All - + + All + + + + + + - + From 1c538a9d11a14fafa6e393e7023acc212c7e5e8c Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:31:18 -0700 Subject: [PATCH 02/28] [SL.Core] Use pattern matching --- src/SixLabors.Core/Primitives/Point.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index ab12e28ff..f302b8218 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/src/SixLabors.Core/Primitives/Point.cs @@ -267,7 +267,7 @@ namespace SixLabors.Primitives } /// - public override bool Equals(object obj) => obj is Point && this.Equals((Point)obj); + public override bool Equals(object obj) => obj is Point other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] From 89ab204a5477435f4a9f45faff6f7293233e7a03 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:31:37 -0700 Subject: [PATCH 03/28] [SL.Core] Remove unused Gaurd overloads --- src/SixLabors.Core/Helpers/Guard.cs | 32 ++++------------ .../Helpers/GuardTests.cs | 37 ------------------- 2 files changed, 7 insertions(+), 62 deletions(-) diff --git a/src/SixLabors.Core/Helpers/Guard.cs b/src/SixLabors.Core/Helpers/Guard.cs index 41db42fc1..069c4eb05 100644 --- a/src/SixLabors.Core/Helpers/Guard.cs +++ b/src/SixLabors.Core/Helpers/Guard.cs @@ -20,19 +20,13 @@ namespace SixLabors /// /// The target object, which cannot be null. /// The name of the parameter that is to be checked. - /// The error message, if any to add to the exception. /// is null /// The type of the object to verify - public static void NotNull(T target, string parameterName, string message = "") + public static void NotNull(T target, string parameterName) where T : class { - if (target == null) + if (target is null) { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentNullException(parameterName, message); - } - throw new ArgumentNullException(parameterName); } } @@ -44,20 +38,14 @@ namespace SixLabors /// /// The target string, which should be checked against being null or empty. /// Name of the parameter. - /// The error message, if any to add to the exception. /// is null. /// is empty or contains only blanks. - public static void NotNullOrEmpty(string target, string parameterName, string message = "") + public static void NotNullOrEmpty(string target, string parameterName) { - NotNull(target, parameterName, message); + NotNull(target, parameterName); if (string.IsNullOrWhiteSpace(target)) { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentException(message, parameterName); - } - throw new ArgumentException("Value cannot be null, empty, or cannot contain only whitespace.", parameterName); } } @@ -68,20 +56,14 @@ namespace SixLabors /// The type of objects in the /// The target enumeration, which should be checked against being null or empty. /// Name of the parameter. - /// The error message, if any to add to the exception. /// is null. /// is empty. - public static void NotNullOrEmpty(IEnumerable target, string parameterName, string message = "") + public static void NotNullOrEmpty(IEnumerable target, string parameterName) { - NotNull(target, parameterName, message); + NotNull(target, parameterName); if (!target.Any()) { - if (!string.IsNullOrWhiteSpace(message)) - { - throw new ArgumentException(message, parameterName); - } - throw new ArgumentException("Value cannot be empty.", parameterName); } } @@ -247,4 +229,4 @@ namespace SixLabors } } } -} +} \ No newline at end of file diff --git a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs index ed2e0b5c7..b3f1b96a0 100644 --- a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Xunit; namespace SixLabors.Helpers.Tests @@ -25,18 +24,6 @@ namespace SixLabors.Helpers.Tests }); } - [Fact] - public void NotNull_TargetNullWithMessage_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNull((object)null, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - [Fact] public void NotNullOrEmpty_TargetNotNullOrEmpty_ThrowsNoException() { @@ -73,18 +60,6 @@ namespace SixLabors.Helpers.Tests Assert.True(exception.Message.Contains("Value cannot be null, empty, or cannot contain only whitespace.")); } - [Fact] - public void NotNullOrEmpty_TargetEmptyWithMessage_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNullOrEmpty(string.Empty, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - [Fact] public void NotNullOrEmptyIEnumerable_TargetNotNullOrEmpty_ThrowsNoException() { @@ -112,18 +87,6 @@ namespace SixLabors.Helpers.Tests Assert.True(exception.Message.Contains("Value cannot be empty.")); } - [Fact] - public void NotNullOrEmptyIEnumerable_TargetEmptyWithMessage_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNullOrEmpty(new string[] { }, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - [Fact] public void MustBeLessThan_IsLess_ThrowsNoException() { From 78b622d6875183ca7cbbde6e09bb469802b24994 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:32:58 -0700 Subject: [PATCH 04/28] [SL.Core] Seal ManagedByteBuffer --- .../Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs b/src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs index 31096d3a9..0b0d6c4d4 100644 --- a/src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs +++ b/src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs @@ -51,7 +51,7 @@ namespace SixLabors.Memory /// protected override void Dispose(bool disposing) { - if (!disposing || this.Data == null || this.sourcePoolReference == null) + if (!disposing || this.Data is null || this.sourcePoolReference is null) { return; } @@ -71,7 +71,7 @@ namespace SixLabors.Memory /// /// The implementation of . /// - private class ManagedByteBuffer : Buffer, IManagedByteBuffer + private sealed class ManagedByteBuffer : Buffer, IManagedByteBuffer { public ManagedByteBuffer(byte[] data, int length, ArrayPool sourcePool) : base(data, length, sourcePool) From 2b23f81666336fa01aff7e80759ba371d39f9a60 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:43:50 -0700 Subject: [PATCH 05/28] [SL.Core] Extend HashHelper.Combine to accept 2, 3, or 4 args --- src/SixLabors.Core/Helpers/HashHelpers.cs | 36 ++++++++++++++++++++- src/SixLabors.Core/Primitives/Rectangle.cs | 11 ++++--- src/SixLabors.Core/Primitives/RectangleF.cs | 11 ++++--- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/SixLabors.Core/Helpers/HashHelpers.cs b/src/SixLabors.Core/Helpers/HashHelpers.cs index 40a2b3f96..a453a53de 100644 --- a/src/SixLabors.Core/Helpers/HashHelpers.cs +++ b/src/SixLabors.Core/Helpers/HashHelpers.cs @@ -13,7 +13,7 @@ namespace SixLabors /// /// Hash code one /// Hash code two - /// Returns a hash code for the two specified has codes. + /// Returns a hash code for the provided hash codes. public static int Combine(int h1, int h2) { unchecked @@ -24,5 +24,39 @@ namespace SixLabors return ((int)rol5 + h1) ^ h2; } } + + /// + /// Combines the three specified hash codes. + /// + /// The first + /// Hash code two + /// Hash code three + /// Returns a hash code for the provided hash codes. + public static int Combine(int h1, int h2, int h3) + { + int hash = Combine(h1, h2); + + hash = Combine(hash, h3); + + return hash; + } + + /// + /// Combines the four specified hash codes. + /// + /// The first + /// Hash code two + /// Hash code three + /// Hash code four + /// Returns a hash code for the provided hash codes. + public static int Combine(int h1, int h2, int h3, int h4) + { + int hash = Combine(h1, h2); + + hash = Combine(hash, h3); + hash = Combine(hash, h4); + + return hash; + } } } diff --git a/src/SixLabors.Core/Primitives/Rectangle.cs b/src/SixLabors.Core/Primitives/Rectangle.cs index 27cba5d15..b68732c40 100644 --- a/src/SixLabors.Core/Primitives/Rectangle.cs +++ b/src/SixLabors.Core/Primitives/Rectangle.cs @@ -460,11 +460,12 @@ namespace SixLabors.Primitives private int GetHashCode(Rectangle rectangle) { - int hashCode = rectangle.X.GetHashCode(); - hashCode = HashHelpers.Combine(hashCode, rectangle.Y.GetHashCode()); - hashCode = HashHelpers.Combine(hashCode, rectangle.Width.GetHashCode()); - hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode()); - return hashCode; + return HashHelpers.Combine( + rectangle.X.GetHashCode(), + rectangle.Y.GetHashCode(), + rectangle.Width.GetHashCode(), + rectangle.Height.GetHashCode() + ); } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/RectangleF.cs b/src/SixLabors.Core/Primitives/RectangleF.cs index d5ee6a61b..a33d227e0 100644 --- a/src/SixLabors.Core/Primitives/RectangleF.cs +++ b/src/SixLabors.Core/Primitives/RectangleF.cs @@ -393,11 +393,12 @@ namespace SixLabors.Primitives private int GetHashCode(RectangleF rectangle) { - int hashCode = rectangle.X.GetHashCode(); - hashCode = HashHelpers.Combine(hashCode, rectangle.Y.GetHashCode()); - hashCode = HashHelpers.Combine(hashCode, rectangle.Width.GetHashCode()); - hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode()); - return hashCode; + return HashHelpers.Combine( + rectangle.X.GetHashCode(), + rectangle.Y.GetHashCode(), + rectangle.Width.GetHashCode(), + rectangle.Height.GetHashCode() + ); } } } \ No newline at end of file From 07a890099704d49c63ec73c364fe76bfd9d2c7d9 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:46:21 -0700 Subject: [PATCH 06/28] [SL.Core] Update Moq & xunit --- tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj b/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj index d23fb956a..da61cd0b8 100644 --- a/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj +++ b/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj @@ -28,10 +28,10 @@ - - - - + + + + From e9a98c257fa803ca8222680c29c4db9f84b6c807 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:46:30 -0700 Subject: [PATCH 07/28] [SL.Core] Update System.Numerics.Vectors --- src/SixLabors.Core/SixLabors.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SixLabors.Core/SixLabors.Core.csproj b/src/SixLabors.Core/SixLabors.Core.csproj index 65955529d..8215664dc 100644 --- a/src/SixLabors.Core/SixLabors.Core.csproj +++ b/src/SixLabors.Core/SixLabors.Core.csproj @@ -52,6 +52,6 @@ - + \ No newline at end of file From 929007d9a40f0069326fb48349908827b689363a Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:53:44 -0700 Subject: [PATCH 08/28] [SL.Core] Remove unused Gaurd.IsTrue and Gaurd.IsFalse --- src/SixLabors.Core/Helpers/Guard.cs | 42 ------------------- .../Helpers/GuardTests.cs | 36 ---------------- 2 files changed, 78 deletions(-) diff --git a/src/SixLabors.Core/Helpers/Guard.cs b/src/SixLabors.Core/Helpers/Guard.cs index 069c4eb05..0e4ef336d 100644 --- a/src/SixLabors.Core/Helpers/Guard.cs +++ b/src/SixLabors.Core/Helpers/Guard.cs @@ -169,48 +169,6 @@ namespace SixLabors } } - /// - /// Verifies, that the method parameter with specified target value is true - /// and throws an exception if it is found to be so. - /// - /// - /// The target value, which cannot be false. - /// - /// - /// The name of the parameter that is to be checked. - /// - /// - /// The error message, if any to add to the exception. - /// - /// - /// is false - /// - public static void IsTrue(bool value, string parameterName, string message) - { - if (!value) - { - throw new ArgumentException(message, parameterName); - } - } - - /// - /// Verifies, that the method parameter with specified target value is false - /// and throws an exception if it is found to be so. - /// - /// The target value, which cannot be true. - /// The name of the parameter that is to be checked. - /// The error message, if any to add to the exception. - /// - /// is true - /// - public static void IsFalse(bool value, string parameterName, string message) - { - if (value) - { - throw new ArgumentException(message, parameterName); - } - } - /// /// Verifies, that the `target` span has the length of 'minLength', or longer. /// diff --git a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs index b3f1b96a0..fee12db17 100644 --- a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs @@ -190,42 +190,6 @@ namespace SixLabors.Helpers.Tests Assert.True(exception.Message.Contains($"Value must be greater than or equal to {min} and less than or equal to {max}.")); } - [Fact] - public void IsTrue_IsTrue_ThrowsNoException() - { - Guard.IsTrue(true, "myParamName", "myTestMessage"); - } - - [Fact] - public void IsTrue_IsFalse_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.IsTrue(false, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - - [Fact] - public void IsFalse_IsFalse_ThrowsNoException() - { - Guard.IsFalse(false, "myParamName", "myTestMessage"); - } - - [Fact] - public void IsFalse_IsTrue_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.IsFalse(true, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - [Theory] [InlineData(2, 1)] [InlineData(2, 2)] From 0efcc28d6af7c1496173a6b25fe5a8a500cc1acd Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:54:29 -0700 Subject: [PATCH 09/28] [SL.Core] Remove private implementations of GetHashCode (and it's call overhead) --- src/SixLabors.Core/Primitives/Point.cs | 6 ++- src/SixLabors.Core/Primitives/PointF.cs | 16 ++------ src/SixLabors.Core/Primitives/Rectangle.cs | 19 ++++------ src/SixLabors.Core/Primitives/RectangleF.cs | 41 +++++++-------------- src/SixLabors.Core/Primitives/SizeF.cs | 4 +- 5 files changed, 30 insertions(+), 56 deletions(-) diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index f302b8218..e42e2bf69 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/src/SixLabors.Core/Primitives/Point.cs @@ -258,7 +258,10 @@ namespace SixLabors.Primitives public void Offset(Point point) => this.Offset(point.X, point.Y); /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); + } /// public override string ToString() @@ -277,6 +280,5 @@ namespace SixLabors.Primitives private static short LowInt16(int n) => unchecked((short)(n & 0xffff)); - private int GetHashCode(Point point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode()); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/PointF.cs b/src/SixLabors.Core/Primitives/PointF.cs index 7c0431556..699cec8c6 100644 --- a/src/SixLabors.Core/Primitives/PointF.cs +++ b/src/SixLabors.Core/Primitives/PointF.cs @@ -267,7 +267,10 @@ namespace SixLabors.Primitives public void Offset(PointF point) => this.Offset(point.X, point.Y); /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); + } /// public override string ToString() @@ -281,16 +284,5 @@ namespace SixLabors.Primitives /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(PointF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y); - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private int GetHashCode(PointF point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode()); } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/Rectangle.cs b/src/SixLabors.Core/Primitives/Rectangle.cs index b68732c40..5b4ac10a7 100644 --- a/src/SixLabors.Core/Primitives/Rectangle.cs +++ b/src/SixLabors.Core/Primitives/Rectangle.cs @@ -443,7 +443,14 @@ namespace SixLabors.Primitives } /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine( + this.X.GetHashCode(), + this.Y.GetHashCode(), + this.Width.GetHashCode(), + this.Height.GetHashCode()); + } /// public override string ToString() @@ -457,15 +464,5 @@ namespace SixLabors.Primitives /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Rectangle other) => this.X == other.X && this.Y == other.Y && this.Width == other.Width && this.Height == other.Height; - - private int GetHashCode(Rectangle rectangle) - { - return HashHelpers.Combine( - rectangle.X.GetHashCode(), - rectangle.Y.GetHashCode(), - rectangle.Width.GetHashCode(), - rectangle.Height.GetHashCode() - ); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/RectangleF.cs b/src/SixLabors.Core/Primitives/RectangleF.cs index a33d227e0..a7f46db0a 100644 --- a/src/SixLabors.Core/Primitives/RectangleF.cs +++ b/src/SixLabors.Core/Primitives/RectangleF.cs @@ -120,10 +120,7 @@ namespace SixLabors.Primitives public float Top { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.Y; - } + get => this.Y; } /// @@ -132,10 +129,7 @@ namespace SixLabors.Primitives public float Right { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.X + this.Width; - } + get => this.X + this.Width; } /// @@ -144,10 +138,7 @@ namespace SixLabors.Primitives public float Bottom { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.Y + this.Height; - } + get => this.Y + this.Height; } /// @@ -156,10 +147,7 @@ namespace SixLabors.Primitives public float Left { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.X; - } + get => this.X; } /// @@ -376,7 +364,14 @@ namespace SixLabors.Primitives } /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() + { + return HashHelpers.Combine( + this.X.GetHashCode(), + this.Y.GetHashCode(), + this.Width.GetHashCode(), + this.Height.GetHashCode()); + } /// public override string ToString() @@ -385,20 +380,10 @@ namespace SixLabors.Primitives } /// - public override bool Equals(object obj) => obj is RectangleF && this.Equals((RectangleF)obj); + public override bool Equals(object obj) => obj is RectangleF other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(RectangleF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y) && this.Width.Equals(other.Width) && this.Height.Equals(other.Height); - - private int GetHashCode(RectangleF rectangle) - { - return HashHelpers.Combine( - rectangle.X.GetHashCode(), - rectangle.Y.GetHashCode(), - rectangle.Width.GetHashCode(), - rectangle.Height.GetHashCode() - ); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/SizeF.cs b/src/SixLabors.Core/Primitives/SizeF.cs index 13c6552ac..365efdc2a 100644 --- a/src/SixLabors.Core/Primitives/SizeF.cs +++ b/src/SixLabors.Core/Primitives/SizeF.cs @@ -200,7 +200,7 @@ namespace SixLabors.Primitives /// public override int GetHashCode() { - return this.GetHashCode(this); + return HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode()); } /// @@ -224,7 +224,5 @@ namespace SixLabors.Primitives /// Product of type SizeF. private static SizeF Multiply(SizeF size, float multiplier) => new SizeF(size.Width * multiplier, size.Height * multiplier); - - private int GetHashCode(SizeF size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode()); } } \ No newline at end of file From 5c98b1f141634ccfd165564befdeb0805885b6c7 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 11:55:52 -0700 Subject: [PATCH 10/28] [SL.Core] Use expressions --- src/SixLabors.Core/Primitives/Point.cs | 6 +----- src/SixLabors.Core/Primitives/PointF.cs | 5 +---- src/SixLabors.Core/Primitives/Size.cs | 5 +---- src/SixLabors.Core/Primitives/SizeF.cs | 5 +---- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index e42e2bf69..8f9db05b8 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/src/SixLabors.Core/Primitives/Point.cs @@ -264,10 +264,7 @@ namespace SixLabors.Primitives } /// - public override string ToString() - { - return $"Point [ X={this.X}, Y={this.Y} ]"; - } + public override string ToString() => $"Point [ X={this.X}, Y={this.Y} ]"; /// public override bool Equals(object obj) => obj is Point other && this.Equals(other); @@ -279,6 +276,5 @@ namespace SixLabors.Primitives private static short HighInt16(int n) => unchecked((short)((n >> 16) & 0xffff)); private static short LowInt16(int n) => unchecked((short)(n & 0xffff)); - } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/PointF.cs b/src/SixLabors.Core/Primitives/PointF.cs index 699cec8c6..c163da7cd 100644 --- a/src/SixLabors.Core/Primitives/PointF.cs +++ b/src/SixLabors.Core/Primitives/PointF.cs @@ -273,10 +273,7 @@ namespace SixLabors.Primitives } /// - public override string ToString() - { - return $"PointF [ X={this.X}, Y={this.Y} ]"; - } + public override string ToString() => $"PointF [ X={this.X}, Y={this.Y} ]"; /// public override bool Equals(object obj) => obj is PointF && this.Equals((PointF)obj); diff --git a/src/SixLabors.Core/Primitives/Size.cs b/src/SixLabors.Core/Primitives/Size.cs index 57884cf5d..d5ff95ad5 100644 --- a/src/SixLabors.Core/Primitives/Size.cs +++ b/src/SixLabors.Core/Primitives/Size.cs @@ -255,10 +255,7 @@ namespace SixLabors.Primitives public override int GetHashCode() => this.GetHashCode(this); /// - public override string ToString() - { - return $"Size [ Width={this.Width}, Height={this.Height} ]"; - } + public override string ToString() => $"Size [ Width={this.Width}, Height={this.Height} ]"; /// public override bool Equals(object obj) => obj is Size && this.Equals((Size)obj); diff --git a/src/SixLabors.Core/Primitives/SizeF.cs b/src/SixLabors.Core/Primitives/SizeF.cs index 365efdc2a..8dbdd7424 100644 --- a/src/SixLabors.Core/Primitives/SizeF.cs +++ b/src/SixLabors.Core/Primitives/SizeF.cs @@ -204,10 +204,7 @@ namespace SixLabors.Primitives } /// - public override string ToString() - { - return $"SizeF [ Width={this.Width}, Height={this.Height} ]"; - } + public override string ToString() => $"SizeF [ Width={this.Width}, Height={this.Height} ]"; /// public override bool Equals(object obj) => obj is SizeF && this.Equals((SizeF)obj); From 1fddd9fc669984bc33df7842c8ad243c5853af1d Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 12:00:01 -0700 Subject: [PATCH 11/28] [SL.Core] Update tests to target netcoreapp2.1 --- tests/CodeCoverage/CodeCoverage.cmd | 2 +- tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/CodeCoverage/CodeCoverage.cmd b/tests/CodeCoverage/CodeCoverage.cmd index d5318bf7a..347e0338c 100644 --- a/tests/CodeCoverage/CodeCoverage.cmd +++ b/tests/CodeCoverage/CodeCoverage.cmd @@ -10,7 +10,7 @@ cd .. dotnet restore SixLabors.Core.sln dotnet build SixLabors.Core.sln --no-incremental -c release /p:codecov=true -tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\SixLabors.Core.Tests\SixLabors.Core.Tests.csproj --no-build -c release" -searchdirs:"tests\SixLabors.Core.Tests\bin\Release\netcoreapp1.1" -register:user -output:.\SixLabors.Core.Coverage.xml -hideskipped:All -returntargetcode -oldStyle -filter:"+[SixLabors.*]*" +tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\SixLabors.Core.Tests\SixLabors.Core.Tests.csproj --no-build -c release" -searchdirs:"tests\SixLabors.Core.Tests\bin\Release\netcoreapp2.1" -register:user -output:.\SixLabors.Core.Coverage.xml -hideskipped:All -returntargetcode -oldStyle -filter:"+[SixLabors.*]*" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj b/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj index da61cd0b8..64545d082 100644 --- a/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj +++ b/tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj @@ -2,7 +2,7 @@ 0.0.0 - netcoreapp1.1;netcoreapp2.0; + netcoreapp1.1;netcoreapp2.1; SixLabors.Core.Tests SixLabors.Shapes.Tests true @@ -38,8 +38,4 @@ - - - - From 9e4008604f515f9dbe3388bc119ff9bdea400e20 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 12:02:47 -0700 Subject: [PATCH 12/28] [SL.Core] Remove additional unused Guard methods --- src/SixLabors.Core/Helpers/Guard.cs | 58 +------------- .../Helpers/GuardTests.cs | 79 ------------------- 2 files changed, 2 insertions(+), 135 deletions(-) diff --git a/src/SixLabors.Core/Helpers/Guard.cs b/src/SixLabors.Core/Helpers/Guard.cs index 0e4ef336d..b50cd4ab0 100644 --- a/src/SixLabors.Core/Helpers/Guard.cs +++ b/src/SixLabors.Core/Helpers/Guard.cs @@ -14,60 +14,6 @@ namespace SixLabors [DebuggerStepThrough] internal static class Guard { - /// - /// Verifies, that the method parameter with specified object value is not null - /// and throws an exception if it is found to be so. - /// - /// The target object, which cannot be null. - /// The name of the parameter that is to be checked. - /// is null - /// The type of the object to verify - public static void NotNull(T target, string parameterName) - where T : class - { - if (target is null) - { - throw new ArgumentNullException(parameterName); - } - } - - /// - /// Verifies, that the string method parameter with specified object value and message - /// is not null, not empty and does not contain only blanks and throws an exception - /// if the object is null. - /// - /// The target string, which should be checked against being null or empty. - /// Name of the parameter. - /// is null. - /// is empty or contains only blanks. - public static void NotNullOrEmpty(string target, string parameterName) - { - NotNull(target, parameterName); - - if (string.IsNullOrWhiteSpace(target)) - { - throw new ArgumentException("Value cannot be null, empty, or cannot contain only whitespace.", parameterName); - } - } - - /// - /// Verifies, that the enumeration is not null and not empty. - /// - /// The type of objects in the - /// The target enumeration, which should be checked against being null or empty. - /// Name of the parameter. - /// is null. - /// is empty. - public static void NotNullOrEmpty(IEnumerable target, string parameterName) - { - NotNull(target, parameterName); - - if (!target.Any()) - { - throw new ArgumentException("Value cannot be empty.", parameterName); - } - } - /// /// Verifies that the specified value is less than a maximum value /// and throws an exception if it is not. @@ -80,7 +26,7 @@ namespace SixLabors /// is greater than the maximum value. /// public static void MustBeLessThan(TValue value, TValue max, string parameterName) - where TValue : IComparable + where TValue : IComparable { if (value.CompareTo(max) >= 0) { @@ -100,7 +46,7 @@ namespace SixLabors /// is greater than the maximum value. /// public static void MustBeLessThanOrEqualTo(TValue value, TValue max, string parameterName) - where TValue : IComparable + where TValue : IComparable { if (value.CompareTo(max) > 0) { diff --git a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs index fee12db17..f95e46e35 100644 --- a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs @@ -2,91 +2,12 @@ // Licensed under the Apache License, Version 2.0. using System; -using System.Collections.Generic; using Xunit; namespace SixLabors.Helpers.Tests { public class GuardTests { - [Fact] - public void NotNull_TargetNotNull_ThrowsNoException() - { - Guard.NotNull("test", "myParamName"); - } - - [Fact] - public void NotNull_TargetNull_ThrowsException() - { - Assert.Throws(() => - { - Guard.NotNull((object)null, "myParamName"); - }); - } - - [Fact] - public void NotNullOrEmpty_TargetNotNullOrEmpty_ThrowsNoException() - { - Guard.NotNullOrEmpty("test", "myParamName"); - } - - [Fact] - public void NotNullOrEmpty_TargetNull_ThrowsException() - { - Assert.Throws(() => - { - Guard.NotNullOrEmpty(null, "myParamName"); - }); - } - - [Fact] - public void NotNullOrEmpty_TargetWhitespace_ThrowsException() - { - Assert.Throws(() => - { - Guard.NotNullOrEmpty("\n\n", "myParamName"); - }); - } - - [Fact] - public void NotNullOrEmpty_TargetEmpty_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNullOrEmpty(string.Empty, "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("Value cannot be null, empty, or cannot contain only whitespace.")); - } - - [Fact] - public void NotNullOrEmptyIEnumerable_TargetNotNullOrEmpty_ThrowsNoException() - { - Guard.NotNullOrEmpty(new string[] { "test" }, "myParamName"); - } - - [Fact] - public void NotNullOrEmptyIEnumerable_TargetNull_ThrowsException() - { - Assert.Throws(() => - { - Guard.NotNullOrEmpty((IEnumerable)null, "myParamName"); - }); - } - - [Fact] - public void NotNullOrEmptyIEnumerable_TargetEmpty_ThrowsException() - { - var exception = Assert.Throws(() => - { - Guard.NotNullOrEmpty(new string[] { }, "myParamName"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("Value cannot be empty.")); - } - [Fact] public void MustBeLessThan_IsLess_ThrowsNoException() { From 16aa3cf86a9b8be30526a6974c9d09e15205be9e Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 12:03:38 -0700 Subject: [PATCH 13/28] [SL.Core] Remove unused DebugGuard methods --- src/SixLabors.Core/Helpers/DebugGuard.cs | 47 +----------------------- 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/src/SixLabors.Core/Helpers/DebugGuard.cs b/src/SixLabors.Core/Helpers/DebugGuard.cs index f41d7eacf..210b13c99 100644 --- a/src/SixLabors.Core/Helpers/DebugGuard.cs +++ b/src/SixLabors.Core/Helpers/DebugGuard.cs @@ -24,7 +24,7 @@ namespace SixLabors public static void NotNull(T target, string parameterName) where T : class { - if (target == null) + if (target is null) { throw new ArgumentNullException(parameterName); } @@ -115,50 +115,7 @@ namespace SixLabors throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min}."); } } - - /// - /// Verifies, that the method parameter with specified target value is true - /// and throws an exception if it is found to be so. - /// - /// - /// The target value, which cannot be false. - /// - /// - /// The name of the parameter that is to be checked. - /// - /// - /// The error message, if any to add to the exception. - /// - /// - /// is false - /// - [Conditional("DEBUG")] - public static void IsTrue(bool target, string parameterName, string message) - { - if (!target) - { - throw new ArgumentException(message, parameterName); - } - } - - /// - /// Verifies, that the method parameter with specified target value is false - /// and throws an exception if it is found to be so. - /// - /// The target value, which cannot be true. - /// The name of the parameter that is to be checked. - /// The error message, if any to add to the exception. - /// - /// is true - /// - [Conditional("DEBUG")] - public static void IsFalse(bool target, string parameterName, string message) - { - if (target) - { - throw new ArgumentException(message, parameterName); - } - } + /// /// Verifies, that the `target` array has declared the length or longer. From 5caeb21467ff80078eb4234110dd9526b6f20c20 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 12:12:43 -0700 Subject: [PATCH 14/28] [SL.Core] Remove whitespace --- src/SixLabors.Core/Helpers/DebugGuard.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SixLabors.Core/Helpers/DebugGuard.cs b/src/SixLabors.Core/Helpers/DebugGuard.cs index 210b13c99..f1fc1c64c 100644 --- a/src/SixLabors.Core/Helpers/DebugGuard.cs +++ b/src/SixLabors.Core/Helpers/DebugGuard.cs @@ -115,7 +115,6 @@ namespace SixLabors throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min}."); } } - /// /// Verifies, that the `target` array has declared the length or longer. From 2aa5bdee5ea13b22cd04b32969f9f5e458e9770b Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 24 Aug 2018 14:45:41 -0700 Subject: [PATCH 15/28] [SL.Core] Remove unused DebugGaurd tests --- .../Helpers/DebugGuardTests.cs | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs index 843b74ded..f3db76ef5 100644 --- a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs @@ -5,7 +5,6 @@ #define DEBUG using System; -using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; @@ -123,42 +122,6 @@ namespace SixLabors.Helpers.Tests Assert.True(exception.Message.Contains($"Value must be greater than or equal to 2.")); } - [Fact] - public void IsTrue_IsTrue_ThrowsNoException() - { - DebugGuard.IsTrue(true, "myParamName", "myTestMessage"); - } - - [Fact] - public void IsTrue_IsFalse_ThrowsException() - { - var exception = Assert.Throws(() => - { - DebugGuard.IsTrue(false, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - - [Fact] - public void IsFalse_IsFalse_ThrowsNoException() - { - DebugGuard.IsFalse(false, "myParamName", "myTestMessage"); - } - - [Fact] - public void IsFalse_IsTrue_ThrowsException() - { - var exception = Assert.Throws(() => - { - DebugGuard.IsFalse(true, "myParamName", "myTestMessage"); - }); - - Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains("myTestMessage")); - } - [Theory] [InlineData(new int[] { 1, 2 }, 1)] [InlineData(new int[] { 1, 2 }, 2)] From 630ff6f9774504efe524e5deb598ea6a6a01efd2 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 27 Aug 2018 07:58:38 -0700 Subject: [PATCH 16/28] [SL.Core] Cleanup AssemblyInfo add SUPPORT_MATHF symbol --- src/SixLabors.Core/MathF.cs | 2 +- src/SixLabors.Core/Properties/AssemblyInfo.cs | 29 ------------------- src/SixLabors.Core/SixLabors.Core.csproj | 29 ++++++++----------- 3 files changed, 13 insertions(+), 47 deletions(-) diff --git a/src/SixLabors.Core/MathF.cs b/src/SixLabors.Core/MathF.cs index 1329dbdae..b0d760ade 100644 --- a/src/SixLabors.Core/MathF.cs +++ b/src/SixLabors.Core/MathF.cs @@ -3,7 +3,7 @@ using System.Runtime.CompilerServices; -#if NETCOREAPP2_0 || NETCOREAPP2_1 +#if SUPPORTS_MATHF [assembly: TypeForwardedTo(typeof(System.MathF))] #else namespace System diff --git a/src/SixLabors.Core/Properties/AssemblyInfo.cs b/src/SixLabors.Core/Properties/AssemblyInfo.cs index 96a40f6f6..5402a1af1 100644 --- a/src/SixLabors.Core/Properties/AssemblyInfo.cs +++ b/src/SixLabors.Core/Properties/AssemblyInfo.cs @@ -1,37 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System.Reflection; -using System.Resources; using System.Runtime.CompilerServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SixLabors.Core")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Six Labors")] -[assembly: AssemblyProduct("SixLabors.Core")] -[assembly: AssemblyCopyright("Copyright (c) Six Labors and contributors.")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.0")] -[assembly: AssemblyFileVersion("0.1.0")] -[assembly: AssemblyInformationalVersion("0.1.0-alpha02")] - // Ensure the internals can be tested. [assembly: InternalsVisibleTo("SixLabors.Core.Tests")] diff --git a/src/SixLabors.Core/SixLabors.Core.csproj b/src/SixLabors.Core/SixLabors.Core.csproj index 8215664dc..b03eac761 100644 --- a/src/SixLabors.Core/SixLabors.Core.csproj +++ b/src/SixLabors.Core/SixLabors.Core.csproj @@ -16,16 +16,7 @@ http://www.apache.org/licenses/LICENSE-2.0 git https://github.com/SixLabors/Core - false - false - false - false - false - false - false - false - false - false + Copyright (c) Six Labors and contributors. full SixLabors @@ -34,24 +25,28 @@ ..\SixLabors.ruleset + + $(DefineConstants);SUPPORTS_MATHF + + - - - - - + All + + + + - + - + \ No newline at end of file From b92ac759556a4e6dda7bdb5a949c15920e59fb30 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 27 Aug 2018 07:59:53 -0700 Subject: [PATCH 17/28] [SL.Core] Add HashHelpersTests --- src/SixLabors.Core/Helpers/HashHelpers.cs | 2 +- .../Helpers/HashHelpersTests.cs | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs diff --git a/src/SixLabors.Core/Helpers/HashHelpers.cs b/src/SixLabors.Core/Helpers/HashHelpers.cs index a453a53de..b1e7ce660 100644 --- a/src/SixLabors.Core/Helpers/HashHelpers.cs +++ b/src/SixLabors.Core/Helpers/HashHelpers.cs @@ -59,4 +59,4 @@ namespace SixLabors return hash; } } -} +} \ No newline at end of file diff --git a/tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs b/tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs new file mode 100644 index 000000000..7091038ad --- /dev/null +++ b/tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs @@ -0,0 +1,28 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using Xunit; + +namespace SixLabors.Tests.Helpers +{ + public class HashHelpersTests + { + [Fact] + public void CanCombineTwoValues() + { + Assert.Equal(35, HashHelpers.Combine(1, 2)); + } + + [Fact] + public void CanCombineThreeValues() + { + Assert.Equal(1152, HashHelpers.Combine(1, 2, 3)); + } + + [Fact] + public void CanCombineFourValues() + { + Assert.Equal(38020, HashHelpers.Combine(1, 2, 3, 4)); + } + } +} \ No newline at end of file From 9e4662d42ff209aa7fa0a34cd9793d296c5c3865 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 27 Aug 2018 08:00:37 -0700 Subject: [PATCH 18/28] [SL.Core] Add test to ensure PointF has the same layout as Vector2 --- tests/SixLabors.Core.Tests/Primitives/PointFTests.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/SixLabors.Core.Tests/Primitives/PointFTests.cs b/tests/SixLabors.Core.Tests/Primitives/PointFTests.cs index 6fdf1bbc3..cdd7410d5 100644 --- a/tests/SixLabors.Core.Tests/Primitives/PointFTests.cs +++ b/tests/SixLabors.Core.Tests/Primitives/PointFTests.cs @@ -5,12 +5,24 @@ using System; using System.Globalization; using System.Numerics; using System.Reflection; +using System.Runtime.CompilerServices; using Xunit; namespace SixLabors.Primitives.Tests { public class PointFTests { + [Fact] + public void CanReinterpretCastFromVector2() + { + var vector = new Vector2(1, 2); + + PointF point = Unsafe.As(ref vector); + + Assert.Equal(vector.X, point.X); + Assert.Equal(vector.Y, point.Y); + } + [Fact] public void DefaultConstructorTest() { From cd39bf858142c0a2394e05942cc1e841a30c709d Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 27 Aug 2018 08:06:05 -0700 Subject: [PATCH 19/28] [SL.Core] Format Rectangle --- src/SixLabors.Core/Primitives/Rectangle.cs | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/SixLabors.Core/Primitives/Rectangle.cs b/src/SixLabors.Core/Primitives/Rectangle.cs index 5b4ac10a7..2c9eec269 100644 --- a/src/SixLabors.Core/Primitives/Rectangle.cs +++ b/src/SixLabors.Core/Primitives/Rectangle.cs @@ -120,10 +120,7 @@ namespace SixLabors.Primitives public int Top { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.Y; - } + get => this.Y; } /// @@ -132,10 +129,7 @@ namespace SixLabors.Primitives public int Right { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return unchecked(this.X + this.Width); - } + get => unchecked(this.X + this.Width); } /// @@ -144,10 +138,8 @@ namespace SixLabors.Primitives public int Bottom { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return unchecked(this.Y + this.Height); - } + get => unchecked(this.Y + this.Height); + } /// @@ -156,10 +148,7 @@ namespace SixLabors.Primitives public int Left { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return this.X; - } + get => this.X; } /// @@ -459,7 +448,7 @@ namespace SixLabors.Primitives } /// - public override bool Equals(object obj) => obj is Rectangle && this.Equals((Rectangle)obj); + public override bool Equals(object obj) => obj is Rectangle other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] From 0a8dea4c2093fda937a757823b4f6f80843e5ed7 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 27 Aug 2018 08:11:59 -0700 Subject: [PATCH 20/28] [SL.Core] Remove whitespace --- src/SixLabors.Core/Properties/AssemblyInfo.cs | 2 +- tests/SixLabors.Core.Tests/Helpers/MathFTests.cs | 1 + .../SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SixLabors.Core/Properties/AssemblyInfo.cs b/src/SixLabors.Core/Properties/AssemblyInfo.cs index 5402a1af1..92c683b13 100644 --- a/src/SixLabors.Core/Properties/AssemblyInfo.cs +++ b/src/SixLabors.Core/Properties/AssemblyInfo.cs @@ -12,4 +12,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("SixLabors.ImageSharp")] [assembly: InternalsVisibleTo("SixLabors.ImageSharp.Drawing")] [assembly: InternalsVisibleTo("SixLabors.Shapes")] -[assembly: InternalsVisibleTo("SixLabors.Shapes.Text")] +[assembly: InternalsVisibleTo("SixLabors.Shapes.Text")] \ No newline at end of file diff --git a/tests/SixLabors.Core.Tests/Helpers/MathFTests.cs b/tests/SixLabors.Core.Tests/Helpers/MathFTests.cs index 477259983..1d9ea1523 100644 --- a/tests/SixLabors.Core.Tests/Helpers/MathFTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/MathFTests.cs @@ -6,6 +6,7 @@ using Xunit; namespace SixLabors.Tests.Helpers { + public class MathFTests { [Fact] diff --git a/tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs index 0068fce91..6e7efebb8 100644 --- a/tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -80,7 +80,6 @@ namespace SixLabors.Memory.Tests Assert.True(this.CheckIsRentingPooledBuffer(size)); } - [Theory] [InlineData(128 * 1024 * 1024)] [InlineData(MaxPooledBufferSizeInBytes + 1)] From 2f944fcdeda2bf6e4776e6a990f74ab8a1d145ac Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Aug 2018 10:08:56 -0700 Subject: [PATCH 21/28] [SL.Core] Remove aggressive inlining hint from trival accessors --- src/SixLabors.Core/Primitives/Rectangle.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/SixLabors.Core/Primitives/Rectangle.cs b/src/SixLabors.Core/Primitives/Rectangle.cs index 2c9eec269..61dc79916 100644 --- a/src/SixLabors.Core/Primitives/Rectangle.cs +++ b/src/SixLabors.Core/Primitives/Rectangle.cs @@ -117,11 +117,7 @@ namespace SixLabors.Primitives /// /// Gets the y-coordinate of the top edge of this . /// - public int Top - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.Y; - } + public int Top => this.Y; /// /// Gets the x-coordinate of the right edge of this . @@ -145,11 +141,7 @@ namespace SixLabors.Primitives /// /// Gets the x-coordinate of the left edge of this . /// - public int Left - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.X; - } + public int Left => this.X; /// /// Creates a with the coordinates of the specified . From 88203cef84dbb817f055a40e6749398daca3dd17 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Aug 2018 10:09:16 -0700 Subject: [PATCH 22/28] [SL.Core] Format Point --- src/SixLabors.Core/Primitives/Point.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index 8f9db05b8..112d8fea2 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/src/SixLabors.Core/Primitives/Point.cs @@ -258,10 +258,7 @@ namespace SixLabors.Primitives public void Offset(Point point) => this.Offset(point.X, point.Y); /// - public override int GetHashCode() - { - return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); - } + public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); /// public override string ToString() => $"Point [ X={this.X}, Y={this.Y} ]"; From 25484773fb784eba1c82f6cff11e2a3ce47215af Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Aug 2018 10:09:25 -0700 Subject: [PATCH 23/28] [SL.Core] Format HashHelpers --- src/SixLabors.Core/Helpers/HashHelpers.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SixLabors.Core/Helpers/HashHelpers.cs b/src/SixLabors.Core/Helpers/HashHelpers.cs index b1e7ce660..934384238 100644 --- a/src/SixLabors.Core/Helpers/HashHelpers.cs +++ b/src/SixLabors.Core/Helpers/HashHelpers.cs @@ -1,10 +1,12 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; + namespace SixLabors { /// - /// Lifted from coreFX repo + /// Provides a set of helpers for combining object hashes. /// internal static class HashHelpers { @@ -16,6 +18,8 @@ namespace SixLabors /// Returns a hash code for the provided hash codes. public static int Combine(int h1, int h2) { + // Lifted from coreFX repo + unchecked { // RyuJIT optimizes this to use the ROL instruction @@ -54,9 +58,8 @@ namespace SixLabors int hash = Combine(h1, h2); hash = Combine(hash, h3); - hash = Combine(hash, h4); - return hash; + return Combine(hash, h4); } } } \ No newline at end of file From 538e1e015e4ea2c77833020c87ecc10b0f391423 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Aug 2018 10:10:07 -0700 Subject: [PATCH 24/28] [SL.Core] Use Assert.Contains when checking for substrings --- tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs | 4 ++-- tests/SixLabors.Core.Tests/Helpers/GuardTests.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs index f3db76ef5..68416b47d 100644 --- a/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs @@ -99,7 +99,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"Value must be greater than {min}.")); + Assert.Contains($"Value must be greater than {min}.", exception.Message); } [Theory] @@ -119,7 +119,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"Value must be greater than or equal to 2.")); + Assert.Contains($"Value must be greater than or equal to 2.", exception.Message); } [Theory] diff --git a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs index f95e46e35..ecffd79da 100644 --- a/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs +++ b/tests/SixLabors.Core.Tests/Helpers/GuardTests.cs @@ -65,7 +65,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"Value must be greater than {min}.")); + Assert.Contains($"Value must be greater than {min}.", exception.Message); } [Theory] @@ -108,7 +108,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"Value must be greater than or equal to {min} and less than or equal to {max}.")); + Assert.Contains($"Value must be greater than or equal to {min} and less than or equal to {max}.", exception.Message); } [Theory] @@ -128,7 +128,7 @@ namespace SixLabors.Helpers.Tests }); Assert.Equal("myParamName", exception.ParamName); - Assert.True(exception.Message.Contains($"The size must be at least 3.")); + Assert.Contains("The size must be at least 3.", exception.Message); } } } From 704fa0f8bd2895e58d7f66af5727665933554db6 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Aug 2018 10:15:41 -0700 Subject: [PATCH 25/28] [SL.Core] Remove AggressiveInlining hint from trival accessors --- src/SixLabors.Core/Primitives/RectangleF.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/SixLabors.Core/Primitives/RectangleF.cs b/src/SixLabors.Core/Primitives/RectangleF.cs index a7f46db0a..1a275b623 100644 --- a/src/SixLabors.Core/Primitives/RectangleF.cs +++ b/src/SixLabors.Core/Primitives/RectangleF.cs @@ -117,11 +117,7 @@ namespace SixLabors.Primitives /// /// Gets the y-coordinate of the top edge of this . /// - public float Top - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.Y; - } + public float Top => this.Y; /// /// Gets the x-coordinate of the right edge of this . @@ -144,11 +140,7 @@ namespace SixLabors.Primitives /// /// Gets the x-coordinate of the left edge of this . /// - public float Left - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => this.X; - } + public float Left => this.X; /// /// Creates a with the coordinates of the specified by truncating each coordinate. From 26030cce6d913a032ca34c76d94ef8ae54a7f3a5 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Aug 2018 10:15:48 -0700 Subject: [PATCH 26/28] [SL.Core] Format Size --- src/SixLabors.Core/Primitives/Size.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/SixLabors.Core/Primitives/Size.cs b/src/SixLabors.Core/Primitives/Size.cs index d5ff95ad5..86412a137 100644 --- a/src/SixLabors.Core/Primitives/Size.cs +++ b/src/SixLabors.Core/Primitives/Size.cs @@ -252,17 +252,17 @@ namespace SixLabors.Primitives public static Size Truncate(SizeF size) => new Size(unchecked((int)size.Width), unchecked((int)size.Height)); /// - public override int GetHashCode() => this.GetHashCode(this); + public override int GetHashCode() => HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode()); /// public override string ToString() => $"Size [ Width={this.Width}, Height={this.Height} ]"; /// - public override bool Equals(object obj) => obj is Size && this.Equals((Size)obj); + public override bool Equals(object obj) => obj is Size other && this.Equals(other); /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Size other) => this.Width == other.Width && this.Height == other.Height; + public bool Equals(Size other) => this.Width.Equals(other.Width) && this.Height.Equals(other.Height); /// /// Multiplies by an producing . @@ -281,16 +281,5 @@ namespace SixLabors.Primitives /// Product of type SizeF. private static SizeF Multiply(Size size, float multiplier) => new SizeF(size.Width * multiplier, size.Height * multiplier); - - /// - /// Returns the hash code for this instance. - /// - /// - /// The instance of to return the hash code for. - /// - /// - /// A 32-bit signed integer that is the hash code for this instance. - /// - private int GetHashCode(Size size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode()); } } \ No newline at end of file From e2b7d687f5ee7c865f1507783d1e32f36f65b8a8 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Aug 2018 10:16:03 -0700 Subject: [PATCH 27/28] [SL.Core] Replace == with Equals --- src/SixLabors.Core/Primitives/Point.cs | 2 +- src/SixLabors.Core/Primitives/Rectangle.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index 112d8fea2..de0171796 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/src/SixLabors.Core/Primitives/Point.cs @@ -268,7 +268,7 @@ namespace SixLabors.Primitives /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Point other) => this.X == other.X && this.Y == other.Y; + public bool Equals(Point other) => this.X.Equals(other.X) && this.Y.Equals(other.Y); private static short HighInt16(int n) => unchecked((short)((n >> 16) & 0xffff)); diff --git a/src/SixLabors.Core/Primitives/Rectangle.cs b/src/SixLabors.Core/Primitives/Rectangle.cs index 61dc79916..441c251eb 100644 --- a/src/SixLabors.Core/Primitives/Rectangle.cs +++ b/src/SixLabors.Core/Primitives/Rectangle.cs @@ -444,6 +444,10 @@ namespace SixLabors.Primitives /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Rectangle other) => this.X == other.X && this.Y == other.Y && this.Width == other.Width && this.Height == other.Height; + public bool Equals(Rectangle other) => + this.X.Equals(other.X) && + this.Y.Equals(other.Y) && + this.Width.Equals(other.Width) && + this.Height.Equals(other.Height); } } \ No newline at end of file From 9df8d07b2321fb915f8bd157eb82992b56e764f2 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Fri, 31 Aug 2018 10:17:38 -0700 Subject: [PATCH 28/28] [SL.Core] Format long statement onto multiple lines --- src/SixLabors.Core/Primitives/RectangleF.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SixLabors.Core/Primitives/RectangleF.cs b/src/SixLabors.Core/Primitives/RectangleF.cs index 1a275b623..535705a28 100644 --- a/src/SixLabors.Core/Primitives/RectangleF.cs +++ b/src/SixLabors.Core/Primitives/RectangleF.cs @@ -376,6 +376,10 @@ namespace SixLabors.Primitives /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(RectangleF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y) && this.Width.Equals(other.Width) && this.Height.Equals(other.Height); + public bool Equals(RectangleF other) => + this.X.Equals(other.X) && + this.Y.Equals(other.Y) && + this.Width.Equals(other.Width) && + this.Height.Equals(other.Height); } } \ No newline at end of file