Struct Rectangle
- Namespace
- SixLabors.ImageSharp
- Assembly
- SixLabors.ImageSharp.dll
Stores a set of four integers that represent the location and size of a rectangle.
public struct Rectangle : IEquatable<Rectangle>
- Implements
- Inherited Members
Remarks
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.
Constructors
Rectangle(Point, Size)
Initializes a new instance of the Rectangle struct.
public Rectangle(Point point, Size size)
Parameters
pointPointThe Point which specifies the rectangles point in a two-dimensional plane.
sizeSizeThe Size which specifies the rectangles height and width.
Rectangle(int, int, int, int)
Initializes a new instance of the Rectangle struct.
public Rectangle(int x, int y, int width, int height)
Parameters
xintThe horizontal position of the rectangle.
yintThe vertical position of the rectangle.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
Fields
Empty
Represents a Rectangle that has X, Y, Width, and Height values set to zero.
public static readonly Rectangle Empty
Field Value
Properties
Bottom
Gets the y-coordinate of the bottom edge of this Rectangle.
public int Bottom { get; }
Property Value
Height
Gets or sets the height of this Rectangle.
public int Height { readonly get; set; }
Property Value
Left
Gets the x-coordinate of the left edge of this Rectangle.
public int Left { get; }
Property Value
Right
Gets the x-coordinate of the right edge of this Rectangle.
public int Right { get; }
Property Value
Top
Gets the y-coordinate of the top edge of this Rectangle.
public int Top { get; }
Property Value
Width
Gets or sets the width of this Rectangle.
public int Width { readonly get; set; }
Property Value
X
Gets or sets the x-coordinate of this Rectangle.
public int X { readonly get; set; }
Property Value
Y
Gets or sets the y-coordinate of this Rectangle.
public int Y { readonly get; set; }
Property Value
Methods
Ceiling(RectangleF)
Converts a RectangleF to a Rectangle by performing a ceiling operation on all the coordinates.
public static Rectangle Ceiling(RectangleF rectangle)
Parameters
rectangleRectangleFThe rectangle.
Returns
Center(Rectangle)
Returns the center point of the given Rectangle.
public static Point Center(Rectangle rectangle)
Parameters
rectangleRectangleThe rectangle.
Returns
Contains(Point)
Determines if the specified point is contained within the rectangular region defined by this Rectangle .
public bool Contains(Point point)
Parameters
pointPointThe point.
Returns
Contains(Rectangle)
Determines if the rectangular region represented by rectangle is entirely contained
within the rectangular region represented by this Rectangle .
public bool Contains(Rectangle rectangle)
Parameters
rectangleRectangleThe rectangle.
Returns
Contains(int, int)
Determines if the specified point is contained within the rectangular region defined by this Rectangle.
public bool Contains(int x, int y)
Parameters
Returns
Deconstruct(out int, out int, out int, out int)
Deconstructs this rectangle into four integers.
public void Deconstruct(out int x, out int y, out int width, out int height)
Parameters
xintThe out value for X.
yintThe out value for Y.
widthintThe out value for the width.
heightintThe out value for the height.
Equals(Rectangle)
public bool Equals(Rectangle other)
Parameters
otherRectangle
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
FromLTRB(int, int, int, int)
Creates a new Rectangle with the specified location and size.
public static Rectangle FromLTRB(int left, int top, int right, int bottom)
Parameters
leftintThe left coordinate of the rectangle.
topintThe top coordinate of the rectangle.
rightintThe right coordinate of the rectangle.
bottomintThe bottom coordinate of the rectangle.
Returns
GetHashCode()
public override int GetHashCode()
Returns
Inflate(Rectangle, int, int)
Creates a Rectangle that is inflated by the specified amount.
public static Rectangle Inflate(Rectangle rectangle, int x, int y)
Parameters
rectangleRectangleThe rectangle.
xintThe amount to inflate the width by.
yintThe amount to inflate the height by.
Returns
Inflate(Size)
Inflates this Rectangle by the specified amount.
public void Inflate(Size size)
Parameters
sizeSizeThe size.
Inflate(int, int)
Inflates this Rectangle by the specified amount.
public void Inflate(int width, int height)
Parameters
Intersect(Rectangle)
Creates a Rectangle that represents the intersection between this Rectangle and the rectangle.
public void Intersect(Rectangle rectangle)
Parameters
rectangleRectangleThe rectangle.
Intersect(Rectangle, Rectangle)
Creates a rectangle that represents the intersection between a and
b. If there is no intersection, an empty rectangle is returned.
public static Rectangle Intersect(Rectangle a, Rectangle b)
Parameters
Returns
IntersectsWith(Rectangle)
public bool IntersectsWith(Rectangle rectangle)
Parameters
rectangleRectangleThe other Rectangle.
Returns
Offset(Point)
Adjusts the location of this rectangle by the specified amount.
public void Offset(Point point)
Parameters
pointPointThe point.
Offset(int, int)
Adjusts the location of this rectangle by the specified amount.
public void Offset(int dx, int dy)
Parameters
Round(RectangleF)
Converts a RectangleF to a Rectangle by performing a round operation on all the coordinates.
public static Rectangle Round(RectangleF rectangle)
Parameters
rectangleRectangleFThe rectangle.
Returns
ToString()
public override string ToString()
Returns
Transform(Rectangle, Matrix3x2)
Transforms a rectangle by the given matrix.
public static RectangleF Transform(Rectangle rectangle, Matrix3x2 matrix)
Parameters
Returns
- RectangleF
A transformed rectangle.
Truncate(RectangleF)
Converts a RectangleF to a Rectangle by performing a truncate operation on all the coordinates.
public static Rectangle Truncate(RectangleF rectangle)
Parameters
rectangleRectangleFThe rectangle.
Returns
Union(Rectangle, Rectangle)
Creates a rectangle that represents the union between a and b.
public static Rectangle Union(Rectangle a, Rectangle b)
Parameters
Returns
Operators
operator ==(Rectangle, Rectangle)
Compares two Rectangle objects for equality.
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
leftRectangleThe Rectangle on the left side of the operand.
rightRectangleThe Rectangle on the right side of the operand.
Returns
- bool
True if the current left is equal to the
rightparameter; otherwise, false.
implicit operator RectangleF(Rectangle)
Creates a RectangleF with the coordinates of the specified Rectangle.
public static implicit operator RectangleF(Rectangle rectangle)
Parameters
rectangleRectangleThe rectangle.
Returns
implicit operator Vector4(Rectangle)
public static implicit operator Vector4(Rectangle rectangle)
Parameters
rectangleRectangleThe rectangle.
Returns
operator !=(Rectangle, Rectangle)
Compares two Rectangle objects for inequality.
public static bool operator !=(Rectangle left, Rectangle right)
Parameters
leftRectangleThe Rectangle on the left side of the operand.
rightRectangleThe Rectangle on the right side of the operand.
Returns
- bool
True if the current left is unequal to the
rightparameter; otherwise, false.