diff --git a/src/ImageProcessor/Colors/Bgra.cs b/src/ImageProcessor/Colors/Bgra.cs
index 8022558ee..c18f3eb49 100644
--- a/src/ImageProcessor/Colors/Bgra.cs
+++ b/src/ImageProcessor/Colors/Bgra.cs
@@ -44,31 +44,31 @@ namespace ImageProcessor
/// Holds the blue component of the color
///
[FieldOffset(0)]
- public byte B;
+ public readonly byte B;
///
/// Holds the green component of the color
///
[FieldOffset(1)]
- public byte G;
+ public readonly byte G;
///
/// Holds the red component of the color
///
[FieldOffset(2)]
- public byte R;
+ public readonly byte R;
///
/// Holds the alpha component of the color
///
[FieldOffset(3)]
- public byte A;
+ public readonly byte A;
///
/// Permits the to be treated as a 32 bit integer.
///
[FieldOffset(0)]
- public int BGRA;
+ public readonly int BGRA;
///
/// Initializes a new instance of the struct.
@@ -142,7 +142,7 @@ namespace ImageProcessor
if (hex.Length != 8 && hex.Length != 6 && hex.Length != 3)
{
- throw new ArgumentException("Hexadecimal string is not in the correct format.", "hex");
+ throw new ArgumentException("Hexadecimal string is not in the correct format.", nameof(hex));
}
if (hex.Length == 8)
@@ -176,13 +176,7 @@ namespace ImageProcessor
/// Gets a value indicating whether this is empty.
///
[EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsEmpty
- {
- get
- {
- return this.B == 0 && this.G == 0 && this.R == 0 && this.A == 0;
- }
- }
+ public bool IsEmpty => this.B == 0 && this.G == 0 && this.R == 0 && this.A == 0;
///
/// Compares two objects. The result specifies whether the values
@@ -249,7 +243,14 @@ namespace ImageProcessor
///
public override int GetHashCode()
{
- return this.GetHashCode(this);
+ unchecked
+ {
+ int hashCode = this.B.GetHashCode();
+ hashCode = (hashCode * 397) ^ this.G.GetHashCode();
+ hashCode = (hashCode * 397) ^ this.R.GetHashCode();
+ hashCode = (hashCode * 397) ^ this.A.GetHashCode();
+ return hashCode;
+ }
}
///
@@ -265,7 +266,7 @@ namespace ImageProcessor
return "Color [ Empty ]";
}
- return string.Format("Color [ B={0}, G={1}, R={2}, A={3} ]", this.B, this.G, this.R, this.A);
+ return $"Color [ B={this.B}, G={this.G}, R={this.R}, A={this.A} ]";
}
///
@@ -277,29 +278,7 @@ namespace ImageProcessor
/// An object to compare with this object.
public bool Equals(Bgra other)
{
- return this.B.Equals(other.B) && this.G.Equals(other.G)
- && this.R.Equals(other.R) && this.A.Equals(other.A);
- }
-
- ///
- /// Returns the hash code for the given 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(Bgra color)
- {
- unchecked
- {
- int hashCode = color.B.GetHashCode();
- hashCode = (hashCode * 397) ^ color.G.GetHashCode();
- hashCode = (hashCode * 397) ^ color.R.GetHashCode();
- hashCode = (hashCode * 397) ^ color.A.GetHashCode();
- return hashCode;
- }
+ return this.BGRA == other.BGRA;
}
}
}
diff --git a/src/ImageProcessor/Colors/YCbCr.cs b/src/ImageProcessor/Colors/YCbCr.cs
index 389d76b25..37be0765b 100644
--- a/src/ImageProcessor/Colors/YCbCr.cs
+++ b/src/ImageProcessor/Colors/YCbCr.cs
@@ -31,19 +31,19 @@ namespace ImageProcessor
/// Holds the Y luminance component.
/// A value ranging between 0 and 255.
///
- public float Y;
+ public float Y { get; }
///
/// Holds the Cb chroma component.
/// A value ranging between 0 and 255.
///
- public float Cb;
+ public float Cb { get; }
///
/// Holds the Cr chroma component.
/// A value ranging between 0 and 255.
///
- public float Cr;
+ public float Cr { get; }
///
/// The epsilon for comparing floating point numbers.
@@ -67,15 +67,9 @@ namespace ImageProcessor
/// Gets a value indicating whether this is empty.
///
[EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsEmpty
- {
- get
- {
- return Math.Abs(this.Y) < Epsilon
- && Math.Abs(this.Cb) < Epsilon
- && Math.Abs(this.Cr) < Epsilon;
- }
- }
+ public bool IsEmpty => Math.Abs(this.Y) < Epsilon
+ && Math.Abs(this.Cb) < Epsilon
+ && Math.Abs(this.Cr) < Epsilon;
///
/// Compares two objects. The result specifies whether the values
@@ -190,7 +184,13 @@ namespace ImageProcessor
///
public override int GetHashCode()
{
- return this.GetHashCode(this);
+ unchecked
+ {
+ int hashCode = this.Y.GetHashCode();
+ hashCode = (hashCode * 397) ^ this.Cb.GetHashCode();
+ hashCode = (hashCode * 397) ^ this.Cr.GetHashCode();
+ return hashCode;
+ }
}
///
@@ -206,7 +206,7 @@ namespace ImageProcessor
return "YCbCrColor [ Empty ]";
}
- return string.Format("YCbCrColor [ Y={0:#0.##}, Cb={1:#0.##}, Cr={2:#0.##} ]", this.Y, this.Cb, this.Cr);
+ return $"YCbCrColor [ Y={this.Y:#0.##}, Cb={this.Cb:#0.##}, Cr={this.Cr:#0.##} ]";
}
///
@@ -222,25 +222,5 @@ namespace ImageProcessor
&& this.Cb.Equals(other.Cb)
&& this.Cr.Equals(other.Cr);
}
-
- ///
- /// Returns the hash code for the given 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(YCbCr color)
- {
- unchecked
- {
- int hashCode = color.Y.GetHashCode();
- hashCode = (hashCode * 397) ^ color.Cb.GetHashCode();
- hashCode = (hashCode * 397) ^ color.Cr.GetHashCode();
- return hashCode;
- }
- }
}
}
diff --git a/src/ImageProcessor/Common/Helpers/Guard.cs b/src/ImageProcessor/Common/Helpers/Guard.cs
index d842685ca..438831fa0 100644
--- a/src/ImageProcessor/Common/Helpers/Guard.cs
+++ b/src/ImageProcessor/Common/Helpers/Guard.cs
@@ -91,7 +91,7 @@ namespace ImageProcessor
{
throw new ArgumentOutOfRangeException(
parameterName,
- string.Format(CultureInfo.CurrentCulture, "Value must be less than {0}.", max));
+ $"Value must be less than {max}.");
}
}
@@ -112,7 +112,7 @@ namespace ImageProcessor
{
throw new ArgumentOutOfRangeException(
parameterName,
- string.Format(CultureInfo.CurrentCulture, "Value must be less than or equal to {0}.", max));
+ $"Value must be less than or equal to {max}.");
}
}
@@ -133,7 +133,7 @@ namespace ImageProcessor
{
throw new ArgumentOutOfRangeException(
parameterName,
- string.Format(CultureInfo.CurrentCulture, "Value must be greater than {0}.", min));
+ $"Value must be greater than {min}.");
}
}
@@ -154,7 +154,7 @@ namespace ImageProcessor
{
throw new ArgumentOutOfRangeException(
parameterName,
- string.Format(CultureInfo.CurrentCulture, "Value must be greater than or equal to {0}.", min));
+ $"Value must be greater than or equal to {min}.");
}
}
@@ -176,7 +176,7 @@ namespace ImageProcessor
{
throw new ArgumentOutOfRangeException(
parameterName,
- string.Format(CultureInfo.CurrentCulture, "Value must be greater than or equal to {0} and less than or equal to {1}.", min, max));
+ $"Value must be greater than or equal to {min} and less than or equal to {max}.");
}
}
}
diff --git a/src/ImageProcessor/Formats/Bmp/BmpDecoder.cs b/src/ImageProcessor/Formats/Bmp/BmpDecoder.cs
index 01f5ba5c3..038324fba 100644
--- a/src/ImageProcessor/Formats/Bmp/BmpDecoder.cs
+++ b/src/ImageProcessor/Formats/Bmp/BmpDecoder.cs
@@ -34,13 +34,7 @@ namespace ImageProcessor.Formats
/// Gets the size of the header for this image type.
///
/// The size of the header.
- public int HeaderSize
- {
- get
- {
- return 2;
- }
- }
+ public int HeaderSize => 2;
///
/// Returns a value indicating whether the supports the specified
diff --git a/src/ImageProcessor/Formats/Bmp/BmpDecoderCore.cs b/src/ImageProcessor/Formats/Bmp/BmpDecoderCore.cs
index 4e45c92e8..2b76fb892 100644
--- a/src/ImageProcessor/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageProcessor/Formats/Bmp/BmpDecoderCore.cs
@@ -33,8 +33,6 @@ namespace ImageProcessor.Formats
///
private const int Rgb16BMask = 0x0000001F;
- #region Fields
-
///
/// The stream to decode from.
///
@@ -51,10 +49,6 @@ namespace ImageProcessor.Formats
///
private BmpInfoHeader infoHeader;
- #endregion
-
- #region IImageDecoder Members
-
///
/// Decodes the image from the specified this._stream and sets
/// the data to image.
@@ -99,8 +93,7 @@ namespace ImageProcessor.Formats
{
if (colorMapSize > 255 * 4)
{
- throw new ImageFormatException(
- string.Format("Invalid bmp colormap size '{0}'", colorMapSize));
+ throw new ImageFormatException($"Invalid bmp colormap size '{colorMapSize}'");
}
palette = new byte[colorMapSize];
@@ -111,12 +104,8 @@ namespace ImageProcessor.Formats
if (this.infoHeader.Width > ImageBase.MaxWidth || this.infoHeader.Height > ImageBase.MaxHeight)
{
throw new ArgumentOutOfRangeException(
- string.Format(
- "The input bitmap '{0}x{1}' is bigger then the max allowed size '{2}x{3}'",
- this.infoHeader.Width,
- this.infoHeader.Height,
- ImageBase.MaxWidth,
- ImageBase.MaxHeight));
+ $"The input bitmap '{this.infoHeader.Width}x{this.infoHeader.Height}' is "
+ + $"bigger then the max allowed size '{ImageBase.MaxWidth}x{ImageBase.MaxHeight}'");
}
byte[] imageData = new byte[this.infoHeader.Width * this.infoHeader.Height * 4];
@@ -127,7 +116,7 @@ namespace ImageProcessor.Formats
if (this.infoHeader.HeaderSize != 40)
{
throw new ImageFormatException(
- string.Format("Header Size value '{0}' is not valid.", this.infoHeader.HeaderSize));
+ $"Header Size value '{this.infoHeader.HeaderSize}' is not valid.");
}
if (this.infoHeader.BitsPerPixel == 32)
@@ -416,7 +405,5 @@ namespace ImageProcessor.Formats
Offset = BitConverter.ToInt32(data, 10)
};
}
-
- #endregion
}
}
diff --git a/src/ImageProcessor/Formats/Bmp/BmpEncoder.cs b/src/ImageProcessor/Formats/Bmp/BmpEncoder.cs
index b8a209d60..b563e8183 100644
--- a/src/ImageProcessor/Formats/Bmp/BmpEncoder.cs
+++ b/src/ImageProcessor/Formats/Bmp/BmpEncoder.cs
@@ -28,10 +28,7 @@ namespace ImageProcessor.Formats
///
/// Gets the default file extension for this encoder.
///
- public string Extension
- {
- get { return "BMP"; }
- }
+ public string Extension => "BMP";
///
/// Returns a value indicating whether the supports the specified
diff --git a/src/ImageProcessor/Formats/Png/PngDecoder.cs b/src/ImageProcessor/Formats/Png/PngDecoder.cs
index 96f0dd109..ca4af1338 100644
--- a/src/ImageProcessor/Formats/Png/PngDecoder.cs
+++ b/src/ImageProcessor/Formats/Png/PngDecoder.cs
@@ -39,13 +39,7 @@ namespace ImageProcessor.Formats
/// Gets the size of the header for this image type.
///
/// The size of the header.
- public int HeaderSize
- {
- get
- {
- return 8;
- }
- }
+ public int HeaderSize => 8;
///
/// Returns a value indicating whether the supports the specified
diff --git a/src/ImageProcessor/Formats/Png/PngDecoderCore.cs b/src/ImageProcessor/Formats/Png/PngDecoderCore.cs
index 3ebe49bbb..2036b4edf 100644
--- a/src/ImageProcessor/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageProcessor/Formats/Png/PngDecoderCore.cs
@@ -157,12 +157,8 @@ namespace ImageProcessor.Formats
if (this.header.Width > ImageBase.MaxWidth || this.header.Height > ImageBase.MaxHeight)
{
throw new ArgumentOutOfRangeException(
- string.Format(
- "The input png '{0}x{1}' is bigger then the max allowed size '{2}x{3}'",
- this.header.Width,
- this.header.Height,
- ImageBase.MaxWidth,
- ImageBase.MaxHeight));
+ $"The input png '{this.header.Width}x{this.header.Height}' is bigger thean the "
+ + $"max allowed size '{ImageBase.MaxWidth}x{ImageBase.MaxHeight}'");
}
byte[] pixels = new byte[this.header.Width * this.header.Height * 4];
@@ -483,11 +479,7 @@ namespace ImageProcessor.Formats
{
if (chunk.Length > MaxChunkSize)
{
- throw new ArgumentOutOfRangeException(
- string.Format(
- "Png chunk size '{0}' exceeds the '{1}'",
- chunk.Length,
- MaxChunkSize));
+ throw new ArgumentOutOfRangeException($"Png chunk size '{chunk.Length}' exceeds the maximum '{MaxChunkSize}'");
}
chunk.Data = new byte[chunk.Length];
diff --git a/src/ImageProcessor/Formats/Png/PngEncoder.cs b/src/ImageProcessor/Formats/Png/PngEncoder.cs
index 332b9e92e..ab0f1ac4f 100644
--- a/src/ImageProcessor/Formats/Png/PngEncoder.cs
+++ b/src/ImageProcessor/Formats/Png/PngEncoder.cs
@@ -72,10 +72,7 @@ namespace ImageProcessor.Formats
/// Gets the default file extension for this encoder.
///
/// The default file extension for this encoder.
- public string Extension
- {
- get { return "PNG"; }
- }
+ public string Extension => "PNG";
///
/// Indicates if the image encoder supports the specified
@@ -389,10 +386,7 @@ namespace ImageProcessor.Formats
}
finally
{
- if (memoryStream != null)
- {
- memoryStream.Dispose();
- }
+ memoryStream?.Dispose();
}
int numChunks = bufferLength / MaxBlockSize;
@@ -453,7 +447,7 @@ namespace ImageProcessor.Formats
/// The containing data.
private void WriteChunk(Stream stream, string type, byte[] data)
{
- this.WriteChunk(stream, type, data, 0, data != null ? data.Length : 0);
+ this.WriteChunk(stream, type, data, 0, data?.Length ?? 0);
}
///
diff --git a/src/ImageProcessor/Image.cs b/src/ImageProcessor/Image.cs
index eeadc2a09..fe81e5f79 100644
--- a/src/ImageProcessor/Image.cs
+++ b/src/ImageProcessor/Image.cs
@@ -18,7 +18,7 @@ namespace ImageProcessor
using System.Linq;
using System.Text;
- using ImageProcessor.Formats;
+ using Formats;
///
/// Image class which stores the pixels and provides common functionality
@@ -66,16 +66,6 @@ namespace ImageProcessor
new PngEncoder(),
});
- ///
- /// The collection of image frames.
- ///
- private readonly IList frames = new List();
-
- ///
- /// The collection of image properties.
- ///
- private readonly IList properties = new List();
-
///
/// Initializes a new instance of the class.
///
@@ -152,18 +142,12 @@ namespace ImageProcessor
///
/// Gets a list of default decoders.
///
- public static IList Decoders
- {
- get { return DefaultDecoders.Value; }
- }
+ public static IList Decoders => DefaultDecoders.Value;
///
/// Gets a list of default encoders.
///
- public static IList Encoders
- {
- get { return DefaultEncoders.Value; }
- }
+ public static IList Encoders => DefaultEncoders.Value;
///
/// Gets or sets the frame delay.
@@ -236,28 +220,19 @@ namespace ImageProcessor
///
/// true if this image is animated; otherwise, false.
///
- public bool IsAnimated
- {
- get { return this.frames.Count > 0; }
- }
+ public bool IsAnimated => this.Frames.Count > 0;
///
/// Gets the other frames for the animation.
///
/// The list of frame images.
- public IList Frames
- {
- get { return this.frames; }
- }
+ public IList Frames { get; } = new List();
///
/// Gets the list of properties for storing meta information about this image.
///
/// A list of image properties.
- public IList Properties
- {
- get { return this.properties; }
- }
+ public IList Properties { get; } = new List();
///
/// Loads the image from the given stream.
diff --git a/src/ImageProcessor/ImageBase.cs b/src/ImageProcessor/ImageBase.cs
index 42605d535..19c1fd809 100644
--- a/src/ImageProcessor/ImageBase.cs
+++ b/src/ImageProcessor/ImageBase.cs
@@ -19,16 +19,6 @@ namespace ImageProcessor
///
public abstract class ImageBase
{
- ///
- /// The maximum allowable width in pixels.
- ///
- private static int maxWidth = int.MaxValue;
-
- ///
- /// The maximum allowable height in pixels.
- ///
- private static int maxHeight = int.MaxValue;
-
///
/// Initializes a new instance of the class.
///
@@ -83,34 +73,12 @@ namespace ImageProcessor
///
/// Gets or sets the maximum allowable width in pixels.
///
- public static int MaxWidth
- {
- get
- {
- return maxWidth;
- }
-
- set
- {
- maxWidth = value;
- }
- }
+ public static int MaxWidth { get; set; } = int.MaxValue;
///
/// Gets or sets the maximum allowable height in pixels.
///
- public static int MaxHeight
- {
- get
- {
- return maxHeight;
- }
-
- set
- {
- maxHeight = value;
- }
- }
+ public static int MaxHeight { get; set; } = int.MaxValue;
///
/// Gets the image pixels as byte array.
@@ -135,21 +103,12 @@ namespace ImageProcessor
///
/// Gets the pixel ratio made up of the width and height.
///
- public double PixelRatio
- {
- get { return (double)this.Width / this.Height; }
- }
+ public double PixelRatio => (double)this.Width / this.Height;
///
/// Gets the representing the bounds of the image.
///
- public Rectangle Bounds
- {
- get
- {
- return new Rectangle(0, 0, this.Width, this.Height);
- }
- }
+ public Rectangle Bounds => new Rectangle(0, 0, this.Width, this.Height);
///
/// Gets or sets the color of a pixel at the specified position.
@@ -170,12 +129,12 @@ namespace ImageProcessor
#if DEBUG
if ((x < 0) || (x >= this.Width))
{
- throw new ArgumentOutOfRangeException("x", "Value cannot be less than zero or greater than the bitmap width.");
+ throw new ArgumentOutOfRangeException(nameof(x), "Value cannot be less than zero or greater than the bitmap width.");
}
if ((y < 0) || (y >= this.Width))
{
- throw new ArgumentOutOfRangeException("y", "Value cannot be less than zero or greater than the bitmap height.");
+ throw new ArgumentOutOfRangeException(nameof(y), "Value cannot be less than zero or greater than the bitmap height.");
}
#endif
@@ -188,12 +147,12 @@ namespace ImageProcessor
#if DEBUG
if ((x < 0) || (x >= this.Width))
{
- throw new ArgumentOutOfRangeException("x", "Value cannot be less than zero or greater than the bitmap width.");
+ throw new ArgumentOutOfRangeException(nameof(x), "Value cannot be less than zero or greater than the bitmap width.");
}
if ((y < 0) || (y >= this.Width))
{
- throw new ArgumentOutOfRangeException("y", "Value cannot be less than zero or greater than the bitmap height.");
+ throw new ArgumentOutOfRangeException(nameof(y), "Value cannot be less than zero or greater than the bitmap height.");
}
#endif
@@ -226,12 +185,12 @@ namespace ImageProcessor
{
if (width <= 0)
{
- throw new ArgumentOutOfRangeException("width", "Width must be greater than or equals than zero.");
+ throw new ArgumentOutOfRangeException(nameof(width), "Width must be greater than or equals than zero.");
}
if (height <= 0)
{
- throw new ArgumentOutOfRangeException("height", "Height must be greater than or equal than zero.");
+ throw new ArgumentOutOfRangeException(nameof(height), "Height must be greater than or equal than zero.");
}
if (pixels.Length != width * height * 4)
diff --git a/src/ImageProcessor/ImageProperty.cs b/src/ImageProcessor/ImageProperty.cs
index bad60c0ef..108a810cb 100644
--- a/src/ImageProcessor/ImageProperty.cs
+++ b/src/ImageProcessor/ImageProperty.cs
@@ -22,19 +22,19 @@ namespace ImageProcessor
public struct ImageProperty : IEquatable
{
///
- /// The name of this indicating which kind of
+ /// Gets the name of this indicating which kind of
/// information this property stores.
///
///
/// Typical properties are the author, copyright
/// information or other meta information.
///
- public string Name;
+ public string Name { get; }
///
/// The value of this .
///
- public string Value;
+ public string Value { get; }
///
/// Initializes a new instance of the struct.
@@ -119,7 +119,12 @@ namespace ImageProcessor
///
public override int GetHashCode()
{
- return this.GetHashCode(this);
+ unchecked
+ {
+ int hashCode = this.Name.GetHashCode();
+ hashCode = (hashCode * 397) ^ this.Value.GetHashCode();
+ return hashCode;
+ }
}
///
@@ -130,7 +135,7 @@ namespace ImageProcessor
///
public override string ToString()
{
- return "{Name=" + this.Name + ",Value=" + this.Value + "}";
+ return $"ImageProperty [ Name={this.Name}, Value={this.Value} ]";
}
///
@@ -144,24 +149,5 @@ namespace ImageProcessor
{
return this.Name.Equals(other.Name) && this.Value.Equals(other.Value);
}
-
- ///
- /// 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(ImageProperty imageProperty)
- {
- unchecked
- {
- int hashCode = imageProperty.Name.GetHashCode();
- hashCode = (hashCode * 397) ^ imageProperty.Value.GetHashCode();
- return hashCode;
- }
- }
}
}
diff --git a/src/ImageProcessor/Numerics/Point.cs b/src/ImageProcessor/Numerics/Point.cs
index ef58cf11d..b70b1af8f 100644
--- a/src/ImageProcessor/Numerics/Point.cs
+++ b/src/ImageProcessor/Numerics/Point.cs
@@ -17,10 +17,25 @@ namespace ImageProcessor
///
/// Represents an ordered pair of integer x- and y-coordinates that defines a point in
- /// a two-dimensional plane.
+ /// a two-dimensional plane.
///
+ ///
+ /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
+ /// as it avoids the need to create new values for modification operations.
+ ///
public struct Point : IEquatable
{
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The horizontal position of the point.
+ /// The vertical position of the point.
+ public Point(int x, int y)
+ {
+ this.X = x;
+ this.Y = y;
+ }
+
///
/// Represents a that has X and Y values set to zero.
///
@@ -29,39 +44,18 @@ namespace ImageProcessor
///
/// The x-coordinate of this .
///
- public int X;
+ public int X { get; set; }
///
/// The y-coordinate of this .
///
- public int Y;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- ///
- /// The horizontal position of the point.
- ///
- ///
- /// The vertical position of the point.
- ///
- public Point(int x, int y)
- {
- this.X = x;
- this.Y = y;
- }
+ public int Y { get; set; }
///
/// Gets a value indicating whether this is empty.
///
[EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsEmpty
- {
- get
- {
- return this.X == 0 && this.Y == 0;
- }
- }
+ public bool IsEmpty => this.X == 0 && this.Y == 0;
///
/// Compares two objects. The result specifies whether the values
@@ -142,7 +136,13 @@ namespace ImageProcessor
///
public override string ToString()
{
- return "{X=" + this.X.ToString(CultureInfo.CurrentCulture) + ",Y=" + this.Y.ToString(CultureInfo.CurrentCulture) + "}";
+ if (this.IsEmpty)
+ {
+ return "Point [ Empty ]";
+ }
+
+ return
+ $"Point [ X={this.X.ToString(CultureInfo.CurrentCulture)}, Y={this.Y.ToString(CultureInfo.CurrentCulture)} ]";
}
///
diff --git a/src/ImageProcessor/Numerics/Rectangle.cs b/src/ImageProcessor/Numerics/Rectangle.cs
index 6028b6de1..f8549a745 100644
--- a/src/ImageProcessor/Numerics/Rectangle.cs
+++ b/src/ImageProcessor/Numerics/Rectangle.cs
@@ -17,48 +17,19 @@ namespace ImageProcessor
///
/// Stores a set of four integers that represent the location and size of a rectangle.
///
+ ///
+ /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
+ /// as it avoids the need to create new values for modification operations.
+ ///
public struct Rectangle : IEquatable
{
- ///
- /// Represents a that has X, Y, Width, and Height values set to zero.
- ///
- public static readonly Rectangle Empty = new Rectangle();
-
- ///
- /// The x-coordinate of this .
- ///
- public int X;
-
- ///
- /// The y-coordinate of this .
- ///
- public int Y;
-
- ///
- /// The width of this .
- ///
- public int Width;
-
- ///
- /// The height of this .
- ///
- public int Height;
-
///
/// Initializes a new instance of the struct.
///
- ///
- /// The horizontal position of the rectangle.
- ///
- ///
- /// The vertical position of the rectangle.
- ///
- ///
- /// The width of the rectangle.
- ///
- ///
- /// The height of the rectangle.
- ///
+ /// The horizontal position of the rectangle.
+ /// The vertical position of the rectangle.
+ /// The width of the rectangle.
+ /// The height of the rectangle.
public Rectangle(int x, int y, int width, int height)
{
this.X = x;
@@ -84,61 +55,56 @@ namespace ImageProcessor
this.Height = size.Height;
}
+ ///
+ /// Represents a that has X, Y, Width, and Height values set to zero.
+ ///
+ public static readonly Rectangle Empty = new Rectangle();
+
+ ///
+ /// The x-coordinate of this .
+ ///
+ public int X { get; set; }
+
+ ///
+ /// The y-coordinate of this .
+ ///
+ public int Y { get; set; }
+
+ ///
+ /// The width of this .
+ ///
+ public int Width { get; set; }
+
+ ///
+ /// The height of this .
+ ///
+ public int Height { get; set; }
+
///
/// Gets a value indicating whether this is empty.
///
[EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsEmpty
- {
- get
- {
- return this.X == 0 && this.Y == 0 && this.Width == 0 && this.Height == 0;
- }
- }
+ public bool IsEmpty => this.X == 0 && this.Y == 0 && this.Width == 0 && this.Height == 0;
///
/// Gets the y-coordinate of the top edge of this .
///
- public int Top
- {
- get
- {
- return this.Y;
- }
- }
+ public int Top => this.Y;
///
/// Gets the x-coordinate of the right edge of this .
///
- public int Right
- {
- get
- {
- return this.X + this.Width;
- }
- }
+ public int Right => this.X + this.Width;
///
/// Gets the y-coordinate of the bottom edge of this .
///
- public int Bottom
- {
- get
- {
- return this.Y + this.Height;
- }
- }
+ public int Bottom => this.Y + this.Height;
///
/// Gets the x-coordinate of the left edge of this .
///
- public int Left
- {
- get
- {
- return this.X;
- }
- }
+ public int Left => this.X;
///
/// Compares two objects. The result specifies whether the values
@@ -219,10 +185,14 @@ namespace ImageProcessor
///
public override string ToString()
{
- return "{X=" + this.X.ToString(CultureInfo.CurrentCulture)
- + ",Y=" + this.Y.ToString(CultureInfo.CurrentCulture)
- + ",Width=" + this.Width.ToString(CultureInfo.CurrentCulture)
- + ",Height=" + this.Height.ToString(CultureInfo.CurrentCulture) + "}";
+ if (this.IsEmpty)
+ {
+ return "Rectangle [ Empty ]";
+ }
+
+ return
+ $"Rectangle [ X={this.X.ToString(CultureInfo.CurrentCulture)}, Y={this.Y.ToString(CultureInfo.CurrentCulture)}, "
+ + $"Width={this.Width.ToString(CultureInfo.CurrentCulture)}, Height={this.Height.ToString(CultureInfo.CurrentCulture)}]";
}
///
diff --git a/src/ImageProcessor/Numerics/Size.cs b/src/ImageProcessor/Numerics/Size.cs
index 42761466b..17382b961 100644
--- a/src/ImageProcessor/Numerics/Size.cs
+++ b/src/ImageProcessor/Numerics/Size.cs
@@ -17,23 +17,12 @@ namespace ImageProcessor
///
/// Stores an ordered pair of integers, which specify a height and width.
///
+ ///
+ /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
+ /// as it avoids the need to create new values for modification operations.
+ ///
public struct Size : IEquatable
{
- ///
- /// Represents a that has Width and Height values set to zero.
- ///
- public static readonly Size Empty = new Size();
-
- ///
- /// The width of this .
- ///
- public int Width;
-
- ///
- /// The height of this .
- ///
- public int Height;
-
///
/// Initializes a new instance of the struct.
///
@@ -49,17 +38,26 @@ namespace ImageProcessor
this.Height = height;
}
+ ///
+ /// Represents a that has Width and Height values set to zero.
+ ///
+ public static readonly Size Empty = new Size();
+
+ ///
+ /// The width of this .
+ ///
+ public int Width { get; set; }
+
+ ///
+ /// The height of this .
+ ///
+ public int Height { get; set; }
+
///
/// Gets a value indicating whether this is empty.
///
[EditorBrowsable(EditorBrowsableState.Never)]
- public bool IsEmpty
- {
- get
- {
- return this.Width == 0 && this.Height == 0;
- }
- }
+ public bool IsEmpty => this.Width == 0 && this.Height == 0;
///
/// Compares two objects. The result specifies whether the values
@@ -137,8 +135,13 @@ namespace ImageProcessor
///
public override string ToString()
{
- return "{Width=" + this.Width.ToString(CultureInfo.CurrentCulture)
- + ",Height=" + this.Height.ToString(CultureInfo.CurrentCulture) + "}";
+ if (this.IsEmpty)
+ {
+ return "Size [ Empty ]";
+ }
+
+ return
+ $"Size [ Width={this.Width.ToString(CultureInfo.CurrentCulture)}, Height={this.Height.ToString(CultureInfo.CurrentCulture)} ]";
}
///
diff --git a/tests/ImageProcessor.Tests/Colors/ColorConversionTests.cs b/tests/ImageProcessor.Tests/Colors/ColorConversionTests.cs
index 836be2e12..1b6c994b8 100644
--- a/tests/ImageProcessor.Tests/Colors/ColorConversionTests.cs
+++ b/tests/ImageProcessor.Tests/Colors/ColorConversionTests.cs
@@ -10,7 +10,6 @@
namespace ImageProcessor.Tests
{
- using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Xunit;