From f58afef9ef6457014c36c741ada3faee46fd8223 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 25 Jun 2017 14:34:29 +0200 Subject: [PATCH] [SL.Core] Fixed all stylecop warnings. --- src/SixLabors.Core/HashHelpers.cs | 19 +++-- src/SixLabors.Core/MathF.cs | 6 +- .../Primitives/Matrix3x2Extensions.cs | 4 +- src/SixLabors.Core/Primitives/Point.cs | 38 +++++----- src/SixLabors.Core/Primitives/PointF.cs | 32 ++++----- src/SixLabors.Core/Primitives/Rectangle.cs | 36 +++++----- src/SixLabors.Core/Primitives/RectangleF.cs | 36 +++++----- src/SixLabors.Core/Primitives/Size.cs | 72 +++++++++---------- src/SixLabors.Core/Primitives/SizeF.cs | 64 ++++++++--------- 9 files changed, 157 insertions(+), 150 deletions(-) diff --git a/src/SixLabors.Core/HashHelpers.cs b/src/SixLabors.Core/HashHelpers.cs index e481e03da..39a94d989 100644 --- a/src/SixLabors.Core/HashHelpers.cs +++ b/src/SixLabors.Core/HashHelpers.cs @@ -1,14 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Text; +// +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. +// namespace SixLabors { - // lifted from coreFX repo + /// + /// Lifted from coreFX repo + /// internal static class HashHelpers { - public static readonly int RandomSeed = Guid.NewGuid().GetHashCode(); - + /// + /// Combines the two specified hash codes. + /// + /// Hash code one + /// Hash code two + /// Returns a hash code for the two specified has codes. public static int Combine(int h1, int h2) { unchecked diff --git a/src/SixLabors.Core/MathF.cs b/src/SixLabors.Core/MathF.cs index b05914e74..d099cb3b8 100644 --- a/src/SixLabors.Core/MathF.cs +++ b/src/SixLabors.Core/MathF.cs @@ -3,11 +3,11 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.Runtime.CompilerServices; + namespace SixLabors { - using System; - using System.Runtime.CompilerServices; - /// /// Provides single-precision floating point constants and static methods for trigonometric, logarithmic, and other common mathematical functions. /// diff --git a/src/SixLabors.Core/Primitives/Matrix3x2Extensions.cs b/src/SixLabors.Core/Primitives/Matrix3x2Extensions.cs index 626be8ed7..c54ce6593 100644 --- a/src/SixLabors.Core/Primitives/Matrix3x2Extensions.cs +++ b/src/SixLabors.Core/Primitives/Matrix3x2Extensions.cs @@ -3,10 +3,10 @@ // Licensed under the Apache License, Version 2.0. // +using System.Numerics; + namespace SixLabors.Primitives { - using System.Numerics; - /// /// Extension methods for the struct. /// diff --git a/src/SixLabors.Core/Primitives/Point.cs b/src/SixLabors.Core/Primitives/Point.cs index ca808c7ef..f21657572 100644 --- a/src/SixLabors.Core/Primitives/Point.cs +++ b/src/SixLabors.Core/Primitives/Point.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; + namespace SixLabors.Primitives { - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; - /// /// Represents an ordered pair of integer x- and y-coordinates that defines a point in /// a two-dimensional plane. @@ -182,7 +182,7 @@ namespace SixLabors.Primitives /// Translates a by the negative of a given value /// /// The point on the left hand of the operand. - /// The size on the right hand of the operand. + /// The value on the right hand of the operand. /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Point Multiply(Point point, int value) => new Point(unchecked(point.X * value), unchecked(point.Y * value)); @@ -212,6 +212,17 @@ namespace SixLabors.Primitives [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Point Round(PointF point) => new Point(unchecked((int)MathF.Round(point.X)), unchecked((int)MathF.Round(point.Y))); + /// + /// Transforms a point by the given matrix. + /// + /// The source point. + /// The transformation matrix. + /// A transformed point. + public static PointF Transform(Point position, Matrix3x2 matrix) + { + return Vector2.Transform(position, matrix); + } + /// /// Converts a to a by performing a truncate operation on all the coordinates. /// @@ -235,7 +246,7 @@ namespace SixLabors.Primitives /// Rotation matrix used /// The rotated [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Point Rotate(Point point, System.Numerics.Matrix3x2 rotation) => Round(Vector2.Transform(new Vector2(point.X, point.Y), rotation)); + public static Point Rotate(Point point, Matrix3x2 rotation) => Round(Vector2.Transform(new Vector2(point.X, point.Y), rotation)); /// /// Skews a point using the given skew matrix. @@ -244,7 +255,7 @@ namespace SixLabors.Primitives /// Rotation matrix used /// The rotated [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Point Skew(Point point, System.Numerics.Matrix3x2 skew) => Round(Vector2.Transform(new Vector2(point.X, point.Y), skew)); + public static Point Skew(Point point, Matrix3x2 skew) => Round(Vector2.Transform(new Vector2(point.X, point.Y), skew)); /// /// Translates this by the specified amount. @@ -289,16 +300,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()); - - /// - /// Transforms a point by the given matrix. - /// - /// The source point - /// The transformation matrix. - /// - public static PointF Transform(Point position, Matrix3x2 matrix) - { - return Vector2.Transform(position, matrix); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/PointF.cs b/src/SixLabors.Core/Primitives/PointF.cs index e2bfa5e50..b4ae390c3 100644 --- a/src/SixLabors.Core/Primitives/PointF.cs +++ b/src/SixLabors.Core/Primitives/PointF.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; + namespace SixLabors.Primitives { - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; - /// /// Represents an ordered pair of single precision floating point x- and y-coordinates that defines a point in /// a two-dimensional plane. @@ -258,6 +258,17 @@ namespace SixLabors.Primitives [MethodImpl(MethodImplOptions.AggressiveInlining)] public static PointF Skew(PointF point, Matrix3x2 skew) => Vector2.Transform(new Vector2(point.X, point.Y), skew); + /// + /// Transforms a point by the given matrix. + /// + /// The source point. + /// The transformation matrix. + /// A transformed point. + public static PointF Transform(PointF position, Matrix3x2 matrix) + { + return Vector2.Transform(position, matrix); + } + /// /// Translates this by the specified amount. /// @@ -303,16 +314,5 @@ namespace SixLabors.Primitives /// 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()); - - /// - /// Transforms a point by the given matrix. - /// - /// The source point - /// The transformation matrix. - /// - public static PointF Transform(PointF position, Matrix3x2 matrix) - { - return Vector2.Transform(position, matrix); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/Rectangle.cs b/src/SixLabors.Core/Primitives/Rectangle.cs index 981eee523..9969e9ba6 100644 --- a/src/SixLabors.Core/Primitives/Rectangle.cs +++ b/src/SixLabors.Core/Primitives/Rectangle.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; + namespace SixLabors.Primitives { - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; - /// /// Stores a set of four integers that represent the location and size of a rectangle. /// @@ -276,6 +276,19 @@ namespace SixLabors.Primitives } } + /// + /// Transforms a rectangle by the given matrix. + /// + /// The source rectangle. + /// The transformation matrix. + /// A transformed rectangle. + public static RectangleF Transform(Rectangle rectangle, Matrix3x2 matrix) + { + PointF bottomRight = Point.Transform(new Point(rectangle.Right, rectangle.Bottom), matrix); + PointF topLeft = Point.Transform(rectangle.Location, matrix); + return new RectangleF(topLeft, new SizeF(bottomRight - topLeft)); + } + /// /// Converts a to a by performing a truncate operation on all the coordinates. /// @@ -455,18 +468,5 @@ namespace SixLabors.Primitives hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode()); return hashCode; } - - /// - /// Transforms a rectangle by the given matrix. - /// - /// The source rectangle - /// The transformation matrix. - /// - public static RectangleF Transform(Rectangle rectangle, Matrix3x2 matrix) - { - PointF bottomRight = Point.Transform(new Point(rectangle.Right, rectangle.Bottom), matrix); - PointF topLeft = Point.Transform(rectangle.Location, matrix); - return new RectangleF(topLeft, new SizeF(bottomRight - topLeft)); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/RectangleF.cs b/src/SixLabors.Core/Primitives/RectangleF.cs index a126008bf..7069006e1 100644 --- a/src/SixLabors.Core/Primitives/RectangleF.cs +++ b/src/SixLabors.Core/Primitives/RectangleF.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; + namespace SixLabors.Primitives { - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; - /// /// Stores a set of four single precision floating points that represent the location and size of a rectangle. /// @@ -251,6 +251,19 @@ namespace SixLabors.Primitives return r; } + /// + /// Transforms a rectangle by the given matrix. + /// + /// The source rectangle. + /// The transformation matrix. + /// A transformed rectangle. + public static RectangleF Transform(RectangleF rectangle, Matrix3x2 matrix) + { + PointF bottomRight = PointF.Transform(new PointF(rectangle.Right, rectangle.Bottom), matrix); + PointF topLeft = PointF.Transform(rectangle.Location, matrix); + return new RectangleF(topLeft, new SizeF(bottomRight - topLeft)); + } + /// /// Creates a rectangle that represents the union between and . /// @@ -388,18 +401,5 @@ namespace SixLabors.Primitives hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode()); return hashCode; } - - /// - /// Transforms a rectangle by the given matrix. - /// - /// The source rectangle - /// The transformation matrix. - /// - public static RectangleF Transform(RectangleF rectangle, Matrix3x2 matrix) - { - PointF bottomRight = PointF.Transform(new PointF(rectangle.Right, rectangle.Bottom), matrix); - PointF topLeft = PointF.Transform(rectangle.Location, matrix); - return new RectangleF(topLeft, new SizeF(bottomRight - topLeft)); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/Size.cs b/src/SixLabors.Core/Primitives/Size.cs index 77aa037cf..893717a35 100644 --- a/src/SixLabors.Core/Primitives/Size.cs +++ b/src/SixLabors.Core/Primitives/Size.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; + namespace SixLabors.Primitives { - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; - /// /// Stores an ordered pair of integers, which specify a height and width. /// @@ -216,24 +216,6 @@ namespace SixLabors.Primitives [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Size Subtract(Size left, Size right) => new Size(unchecked(left.Width - right.Width), unchecked(left.Height - right.Height)); - /// - /// Multiplies by an producing . - /// - /// Multiplicand of type . - /// Multiplier of type . - /// Product of type . - private static Size Multiply(Size size, int multiplier) => - new Size(unchecked(size.Width * multiplier), unchecked(size.Height * multiplier)); - - /// - /// Multiplies by a producing . - /// - /// Multiplicand of type . - /// Multiplier of type . - /// Product of type SizeF. - private static SizeF Multiply(Size size, float multiplier) => - new SizeF(size.Width * multiplier, size.Height * multiplier); - /// /// Converts a to a by performing a ceiling operation on all the dimensions. /// @@ -250,6 +232,19 @@ namespace SixLabors.Primitives [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Size Round(SizeF size) => new Size(unchecked((int)MathF.Round(size.Width)), unchecked((int)MathF.Round(size.Height))); + /// + /// Transforms a size by the given matrix. + /// + /// The source size + /// The transformation matrix. + /// A transformed size. + public static SizeF Transform(Size size, Matrix3x2 matrix) + { + var v = Vector2.Transform(new Vector2(size.Width, size.Height), matrix); + + return new SizeF(v.X, v.Y); + } + /// /// Converts a to a by performing a round operation on all the dimensions. /// @@ -274,6 +269,24 @@ namespace SixLabors.Primitives [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Size other) => this.Width == other.Width && this.Height == other.Height; + /// + /// Multiplies by an producing . + /// + /// Multiplicand of type . + /// Multiplier of type . + /// Product of type . + private static Size Multiply(Size size, int multiplier) => + new Size(unchecked(size.Width * multiplier), unchecked(size.Height * multiplier)); + + /// + /// Multiplies by a producing . + /// + /// Multiplicand of type . + /// Multiplier of type . + /// 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. /// @@ -284,18 +297,5 @@ namespace SixLabors.Primitives /// 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()); - - /// - /// Transforms a size by the given matrix. - /// - /// The source size - /// The transformation matrix. - /// - public static SizeF Transform(Size size, Matrix3x2 matrix) - { - var v = Vector2.Transform(new Vector2(size.Width, size.Height), matrix); - - return new SizeF(v.X, v.Y); - } } } \ No newline at end of file diff --git a/src/SixLabors.Core/Primitives/SizeF.cs b/src/SixLabors.Core/Primitives/SizeF.cs index 9c44e2355..af5d8b0bd 100644 --- a/src/SixLabors.Core/Primitives/SizeF.cs +++ b/src/SixLabors.Core/Primitives/SizeF.cs @@ -3,13 +3,13 @@ // Licensed under the Apache License, Version 2.0. // +using System; +using System.ComponentModel; +using System.Numerics; +using System.Runtime.CompilerServices; + namespace SixLabors.Primitives { - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; - /// /// Stores an ordered pair of single precision floating points, which specify a height and width. /// @@ -72,6 +72,16 @@ namespace SixLabors.Primitives [EditorBrowsable(EditorBrowsableState.Never)] public bool IsEmpty => this.Equals(Empty); + /// + /// Creates a with the coordinates of the specified . + /// + /// The point. + /// + /// The . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Vector2(SizeF point) => new Vector2(point.Width, point.Height); + /// /// Creates a with the dimensions of the specified by truncating each of the dimensions. /// @@ -177,13 +187,17 @@ namespace SixLabors.Primitives public static SizeF Subtract(SizeF left, SizeF right) => new SizeF(left.Width - right.Width, left.Height - right.Height); /// - /// Multiplies by a producing . + /// Transforms a size by the given matrix. /// - /// Multiplicand of type . - /// Multiplier of type . - /// Product of type SizeF. - private static SizeF Multiply(SizeF size, float multiplier) => - new SizeF(size.Width * multiplier, size.Height * multiplier); + /// The source size. + /// The transformation matrix. + /// A transformed size. + public static SizeF Transform(SizeF size, Matrix3x2 matrix) + { + var v = Vector2.Transform(new Vector2(size.Width, size.Height), matrix); + + return new SizeF(v.X, v.Y); + } /// public override int GetHashCode() @@ -204,29 +218,15 @@ namespace SixLabors.Primitives [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(SizeF other) => this.Width.Equals(other.Width) && this.Height.Equals(other.Height); - private int GetHashCode(SizeF size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode()); - /// - /// Creates a with the coordinates of the specified . - /// - /// The point. - /// - /// The . - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator Vector2(SizeF point) => new Vector2(point.Width, point.Height); - - /// - /// Transforms a size by the given matrix. + /// Multiplies by a producing . /// - /// The source size - /// The transformation matrix. - /// - public static SizeF Transform(SizeF size, Matrix3x2 matrix) - { - var v = Vector2.Transform(new Vector2(size.Width, size.Height), matrix); + /// Multiplicand of type . + /// Multiplier of type . + /// Product of type SizeF. + private static SizeF Multiply(SizeF size, float multiplier) => + new SizeF(size.Width * multiplier, size.Height * multiplier); - return new SizeF(v.X, v.Y); - } + private int GetHashCode(SizeF size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode()); } } \ No newline at end of file