Browse Source

Add readonly modifiers to APIs in Rectangle

af/octree-no-pixelmap
Sergio Pedri 6 years ago
parent
commit
fdc873e1d1
  1. 32
      src/ImageSharp/Primitives/Rectangle.cs

32
src/ImageSharp/Primitives/Rectangle.cs

@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp
public Point Location public Point Location
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new Point(this.X, this.Y); readonly get => new Point(this.X, this.Y);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
set set
@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp
public Size Size public Size Size
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new Size(this.Width, this.Height); readonly get => new Size(this.Width, this.Height);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
set set
@ -112,17 +112,17 @@ namespace SixLabors.ImageSharp
/// Gets a value indicating whether this <see cref="Rectangle"/> is empty. /// Gets a value indicating whether this <see cref="Rectangle"/> is empty.
/// </summary> /// </summary>
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
public bool IsEmpty => this.Equals(Empty); public readonly bool IsEmpty => this.Equals(Empty);
/// <summary> /// <summary>
/// Gets the y-coordinate of the top edge of this <see cref="Rectangle"/>. /// Gets the y-coordinate of the top edge of this <see cref="Rectangle"/>.
/// </summary> /// </summary>
public int Top => this.Y; public readonly int Top => this.Y;
/// <summary> /// <summary>
/// Gets the x-coordinate of the right edge of this <see cref="Rectangle"/>. /// Gets the x-coordinate of the right edge of this <see cref="Rectangle"/>.
/// </summary> /// </summary>
public int Right public readonly int Right
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => unchecked(this.X + this.Width); get => unchecked(this.X + this.Width);
@ -131,7 +131,7 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Gets the y-coordinate of the bottom edge of this <see cref="Rectangle"/>. /// Gets the y-coordinate of the bottom edge of this <see cref="Rectangle"/>.
/// </summary> /// </summary>
public int Bottom public readonly int Bottom
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => unchecked(this.Y + this.Height); get => unchecked(this.Y + this.Height);
@ -140,7 +140,7 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Gets the x-coordinate of the left edge of this <see cref="Rectangle"/>. /// Gets the x-coordinate of the left edge of this <see cref="Rectangle"/>.
/// </summary> /// </summary>
public int Left => this.X; public readonly int Left => this.X;
/// <summary> /// <summary>
/// Creates a <see cref="RectangleF"/> with the coordinates of the specified <see cref="Rectangle"/>. /// Creates a <see cref="RectangleF"/> with the coordinates of the specified <see cref="Rectangle"/>.
@ -327,7 +327,7 @@ namespace SixLabors.ImageSharp
/// <param name="y">The out value for Y.</param> /// <param name="y">The out value for Y.</param>
/// <param name="width">The out value for the width.</param> /// <param name="width">The out value for the width.</param>
/// <param name="height">The out value for the height.</param> /// <param name="height">The out value for the height.</param>
public void Deconstruct(out int x, out int y, out int width, out int height) public readonly void Deconstruct(out int x, out int y, out int width, out int height)
{ {
x = this.X; x = this.X;
y = this.Y; y = this.Y;
@ -383,7 +383,7 @@ namespace SixLabors.ImageSharp
/// <param name="y">The y-coordinate of the given point.</param> /// <param name="y">The y-coordinate of the given point.</param>
/// <returns>The <see cref="bool"/>.</returns> /// <returns>The <see cref="bool"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains(int x, int y) => this.X <= x && x < this.Right && this.Y <= y && y < this.Bottom; public readonly bool Contains(int x, int y) => this.X <= x && x < this.Right && this.Y <= y && y < this.Bottom;
/// <summary> /// <summary>
/// Determines if the specified point is contained within the rectangular region defined by this <see cref="Rectangle"/> . /// Determines if the specified point is contained within the rectangular region defined by this <see cref="Rectangle"/> .
@ -391,7 +391,7 @@ namespace SixLabors.ImageSharp
/// <param name="point">The point.</param> /// <param name="point">The point.</param>
/// <returns>The <see cref="bool"/>.</returns> /// <returns>The <see cref="bool"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains(Point point) => this.Contains(point.X, point.Y); public readonly bool Contains(Point point) => this.Contains(point.X, point.Y);
/// <summary> /// <summary>
/// Determines if the rectangular region represented by <paramref name="rectangle"/> is entirely contained /// Determines if the rectangular region represented by <paramref name="rectangle"/> is entirely contained
@ -400,7 +400,7 @@ namespace SixLabors.ImageSharp
/// <param name="rectangle">The rectangle.</param> /// <param name="rectangle">The rectangle.</param>
/// <returns>The <see cref="bool"/>.</returns> /// <returns>The <see cref="bool"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Contains(Rectangle rectangle) => public readonly bool Contains(Rectangle rectangle) =>
(this.X <= rectangle.X) && (rectangle.Right <= this.Right) && (this.X <= rectangle.X) && (rectangle.Right <= this.Right) &&
(this.Y <= rectangle.Y) && (rectangle.Bottom <= this.Bottom); (this.Y <= rectangle.Y) && (rectangle.Bottom <= this.Bottom);
@ -411,7 +411,7 @@ namespace SixLabors.ImageSharp
/// <param name="rectangle">The other Rectange. </param> /// <param name="rectangle">The other Rectange. </param>
/// <returns>The <see cref="bool"/>.</returns> /// <returns>The <see cref="bool"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IntersectsWith(Rectangle rectangle) => public readonly bool IntersectsWith(Rectangle rectangle) =>
(rectangle.X < this.Right) && (this.X < rectangle.Right) && (rectangle.X < this.Right) && (this.X < rectangle.Right) &&
(rectangle.Y < this.Bottom) && (this.Y < rectangle.Bottom); (rectangle.Y < this.Bottom) && (this.Y < rectangle.Bottom);
@ -438,13 +438,13 @@ namespace SixLabors.ImageSharp
} }
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() public override readonly int GetHashCode()
{ {
return HashCode.Combine(this.X, this.Y, this.Width, this.Height); return HashCode.Combine(this.X, this.Y, this.Width, this.Height);
} }
/// <inheritdoc/> /// <inheritdoc/>
public override string ToString() public override readonly string ToString()
{ {
return $"Rectangle [ X={this.X}, Y={this.Y}, Width={this.Width}, Height={this.Height} ]"; return $"Rectangle [ X={this.X}, Y={this.Y}, Width={this.Width}, Height={this.Height} ]";
} }
@ -454,10 +454,10 @@ namespace SixLabors.ImageSharp
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Rectangle other) => public readonly bool Equals(Rectangle other) =>
this.X.Equals(other.X) && this.X.Equals(other.X) &&
this.Y.Equals(other.Y) && this.Y.Equals(other.Y) &&
this.Width.Equals(other.Width) && this.Width.Equals(other.Width) &&
this.Height.Equals(other.Height); this.Height.Equals(other.Height);
} }
} }

Loading…
Cancel
Save