Struct Rectangle
Stores a set of four integers that represent the location and size of a rectangle.
Implements
Inherited Members
Namespace: SixLabors.ImageSharp
Assembly: SixLabors.ImageSharp.dll
Syntax
public struct Rectangle : IEquatable<Rectangle>
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
| Edit this page View SourceRectangle(Point, Size)
Initializes a new instance of the Rectangle struct.
Declaration
public Rectangle(Point point, Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | point | The Point which specifies the rectangles point in a two-dimensional plane. |
| Size | size | The SixLabors.ImageSharp.Rectangle.Size which specifies the rectangles height and width. |
Rectangle(int, int, int, int)
Initializes a new instance of the Rectangle struct.
Declaration
public Rectangle(int x, int y, int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The horizontal position of the rectangle. |
| int | y | The vertical position of the rectangle. |
| int | width | The width of the rectangle. |
| int | height | The height of the rectangle. |
Fields
| Edit this page View SourceEmpty
Represents a Rectangle that has X, Y, Width, and Height values set to zero.
Declaration
public static readonly Rectangle Empty
Field Value
| Type | Description |
|---|---|
| Rectangle |
Properties
| Edit this page View SourceBottom
Gets the y-coordinate of the bottom edge of this Rectangle.
Declaration
public int Bottom { get; }
Property Value
| Type | Description |
|---|---|
| int |
Height
Gets or sets the height of this Rectangle.
Declaration
public int Height { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Left
Gets the x-coordinate of the left edge of this Rectangle.
Declaration
public int Left { get; }
Property Value
| Type | Description |
|---|---|
| int |
Right
Gets the x-coordinate of the right edge of this Rectangle.
Declaration
public int Right { get; }
Property Value
| Type | Description |
|---|---|
| int |
Top
Gets the y-coordinate of the top edge of this Rectangle.
Declaration
public int Top { get; }
Property Value
| Type | Description |
|---|---|
| int |
Width
Gets or sets the width of this Rectangle.
Declaration
public int Width { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| int |
X
Gets or sets the x-coordinate of this Rectangle.
Declaration
public int X { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Y
Gets or sets the y-coordinate of this Rectangle.
Declaration
public int Y { readonly get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
| Edit this page View SourceCeiling(RectangleF)
Converts a RectangleF to a Rectangle by performing a ceiling operation on all the coordinates.
Declaration
public static Rectangle Ceiling(RectangleF rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | rectangle | The rectangle. |
Returns
| Type | Description |
|---|---|
| Rectangle | The Rectangle. |
Center(Rectangle)
Returns the center point of the given Rectangle.
Declaration
public static Point Center(Rectangle rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The rectangle. |
Returns
| Type | Description |
|---|---|
| Point | The Point. |
Contains(Point)
Determines if the specified point is contained within the rectangular region defined by this Rectangle .
Declaration
public bool Contains(Point point)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | point | The point. |
Returns
| Type | Description |
|---|---|
| bool | The bool. |
Contains(Rectangle)
Determines if the rectangular region represented by rectangle is entirely contained
within the rectangular region represented by this Rectangle .
Declaration
public bool Contains(Rectangle rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The rectangle. |
Returns
| Type | Description |
|---|---|
| bool | The bool. |
Contains(int, int)
Determines if the specified point is contained within the rectangular region defined by this Rectangle.
Declaration
public bool Contains(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The x-coordinate of the given point. |
| int | y | The y-coordinate of the given point. |
Returns
| Type | Description |
|---|---|
| bool | The bool. |
Deconstruct(out int, out int, out int, out int)
Deconstructs this rectangle into four integers.
Declaration
public void Deconstruct(out int x, out int y, out int width, out int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The out value for X. |
| int | y | The out value for Y. |
| int | width | The out value for the width. |
| int | height | The out value for the height. |
Equals(Rectangle)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(Rectangle other)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | other | An object to compare with this object. |
Returns
| Type | Description |
|---|---|
| bool | true if the current object is equal to the |
Equals(object?)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current instance. |
Returns
| Type | Description |
|---|---|
| bool | true if |
Overrides
| Edit this page View SourceFromLTRB(int, int, int, int)
Creates a new Rectangle with the specified location and size.
Declaration
public static Rectangle FromLTRB(int left, int top, int right, int bottom)
Parameters
| Type | Name | Description |
|---|---|---|
| int | left | The left coordinate of the rectangle. |
| int | top | The top coordinate of the rectangle. |
| int | right | The right coordinate of the rectangle. |
| int | bottom | The bottom coordinate of the rectangle. |
Returns
| Type | Description |
|---|---|
| Rectangle | The Rectangle. |
GetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A 32-bit signed integer that is the hash code for this instance. |
Overrides
| Edit this page View SourceInflate(Rectangle, int, int)
Creates a Rectangle that is inflated by the specified amount.
Declaration
public static Rectangle Inflate(Rectangle rectangle, int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The rectangle. |
| int | x | The amount to inflate the width by. |
| int | y | The amount to inflate the height by. |
Returns
| Type | Description |
|---|---|
| Rectangle | A new Rectangle. |
Inflate(Size)
Inflates this Rectangle by the specified amount.
Declaration
public void Inflate(Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | size | The size. |
Inflate(int, int)
Inflates this Rectangle by the specified amount.
Declaration
public void Inflate(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | The width. |
| int | height | The height. |
Intersect(Rectangle)
Creates a Rectangle that represents the intersection between this Rectangle and the rectangle.
Declaration
public void Intersect(Rectangle rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The 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.
Declaration
public static Rectangle Intersect(Rectangle a, Rectangle b)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | a | The first rectangle. |
| Rectangle | b | The second rectangle. |
Returns
| Type | Description |
|---|---|
| Rectangle | The Rectangle. |
IntersectsWith(Rectangle)
Declaration
public bool IntersectsWith(Rectangle rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The other Rectangle. |
Returns
| Type | Description |
|---|---|
| bool | The bool. |
Offset(Point)
Adjusts the location of this rectangle by the specified amount.
Declaration
public void Offset(Point point)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | point | The point. |
Offset(int, int)
Adjusts the location of this rectangle by the specified amount.
Declaration
public void Offset(int dx, int dy)
Parameters
| Type | Name | Description |
|---|---|---|
| int | dx | The amount to offset the x-coordinate. |
| int | dy | The amount to offset the y-coordinate. |
Round(RectangleF)
Converts a RectangleF to a Rectangle by performing a round operation on all the coordinates.
Declaration
public static Rectangle Round(RectangleF rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | rectangle | The rectangle. |
Returns
| Type | Description |
|---|---|
| Rectangle | The Rectangle. |
ToString()
Returns the fully qualified type name of this instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | The fully qualified type name. |
Overrides
| Edit this page View SourceTransform(Rectangle, Matrix3x2)
Transforms a rectangle by the given matrix.
Declaration
public static RectangleF Transform(Rectangle rectangle, Matrix3x2 matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The source rectangle. |
| Matrix3x2 | matrix | The transformation matrix. |
Returns
| Type | Description |
|---|---|
| RectangleF | A transformed rectangle. |
Truncate(RectangleF)
Converts a RectangleF to a Rectangle by performing a truncate operation on all the coordinates.
Declaration
public static Rectangle Truncate(RectangleF rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | rectangle | The rectangle. |
Returns
| Type | Description |
|---|---|
| Rectangle | The Rectangle. |
Union(Rectangle, Rectangle)
Creates a rectangle that represents the union between a and b.
Declaration
public static Rectangle Union(Rectangle a, Rectangle b)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | a | The first rectangle. |
| Rectangle | b | The second rectangle. |
Returns
| Type | Description |
|---|---|
| Rectangle | The Rectangle. |
Operators
| Edit this page View Sourceoperator ==(Rectangle, Rectangle)
Compares two Rectangle objects for equality.
Declaration
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | left | The Rectangle on the left side of the operand. |
| Rectangle | right | The Rectangle on the right side of the operand. |
Returns
| Type | Description |
|---|---|
| bool | True if the current left is equal to the |
implicit operator RectangleF(Rectangle)
Creates a RectangleF with the coordinates of the specified Rectangle.
Declaration
public static implicit operator RectangleF(Rectangle rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The rectangle. |
Returns
| Type | Description |
|---|---|
| RectangleF |
implicit operator Vector4(Rectangle)
Declaration
public static implicit operator Vector4(Rectangle rectangle)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The rectangle. |
Returns
| Type | Description |
|---|---|
| Vector4 |
operator !=(Rectangle, Rectangle)
Compares two Rectangle objects for inequality.
Declaration
public static bool operator !=(Rectangle left, Rectangle right)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | left | The Rectangle on the left side of the operand. |
| Rectangle | right | The Rectangle on the right side of the operand. |
Returns
| Type | Description |
|---|---|
| bool | True if the current left is unequal to the |