Rectangle Struct
Represents an axis-aligned rectangle of pixels with exclusive Rectangle.Right and Rectangle.Bottom bounds.
public readonly struct Rectangle : IEquatable<Rectangle>Remarks
The constructor guarantees that X + Width and Y + Height are representable as Int32, so Rectangle.Right and Rectangle.Bottom never overflow.
- Implements
Constructors
| Name | Description |
|---|---|
| Rectangle(Point, Size) | Initializes a new instance of the Rectangle struct. |
| Rectangle(int, int, int, int) | Initializes a new instance of the Rectangle struct. |
Rectangle overloads
Rectangle(Point, Size)
Rectangle.csRectangle(int, int, int, int)
Rectangle.csInitializes a new instance of the Rectangle struct.
Properties
| Name | Description |
|---|---|
| Bottom | Gets the exclusive bottom bound (Y + Height). |
| Empty | Gets an empty rectangle located at the origin. |
| Height | Gets the height. |
| IsEmpty | Gets a value indicating whether the width or the height is zero. |
| Left | Gets the left coordinate (inclusive). Same as Rectangle.X. |
| Location | Gets the top-left corner. |
| Right | Gets the exclusive right bound (X + Width). |
| Size | Gets the size. |
| Top | Gets the top coordinate (inclusive). Same as Rectangle.Y. |
| Width | Gets the width. |
| X | Gets the left coordinate (inclusive). |
| Y | Gets the top coordinate (inclusive). |
Bottom
Rectangle.csEmpty
Rectangle.csHeight
Rectangle.csIsEmpty
Rectangle.csLeft
Rectangle.csLocation
Rectangle.csRight
Rectangle.csSize
Rectangle.csTop
Rectangle.csWidth
Rectangle.csMethods
| Name | Description |
|---|---|
| Contains(Point) | Determines whether the specified point is inside this rectangle. |
| Contains(Rectangle) | Determines whether the specified rectangle is entirely inside this rectangle. |
| Equals(Rectangle) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object?) | Indicates whether this instance and a specified object are equal. |
| FromLTRB(int, int, int, int) | Creates a rectangle from its inclusive left/top and exclusive right/bottom bounds. |
| GetHashCode() | Returns the hash code for this instance. |
| Intersect(Rectangle, Rectangle) | Returns the intersection of two rectangles, or Rectangle.Empty if they do not overlap. |
| IntersectsWith(Rectangle) | Determines whether this rectangle overlaps the specified rectangle by at least one pixel. |
| ToString() | Returns the rectangle formatted as {X},{Y} {Width}x{Height}. |
FromLTRB(int, int, int, int)
Rectangle.csCreates a rectangle from its inclusive left/top and exclusive right/bottom bounds.
Parameters
leftint- The left coordinate (inclusive).
topint- The top coordinate (inclusive).
rightint- The right coordinate (exclusive). Must be greater than or equal to
left. bottomint- The bottom coordinate (exclusive). Must be greater than or equal to
top.
Returns
Rectangle The rectangle.
Exceptions
ArgumentOutOfRangeException- A bound is inverted or the resulting size overflows
Int32.
GetHashCode()
Rectangle.csIntersect(Rectangle, Rectangle)
Rectangle.csIntersectsWith(Rectangle)
Rectangle.csToString()
Rectangle.csOperators
| Name | Description |
|---|---|
| operator ==(Rectangle, Rectangle) | Compares two rectangles for equality. |
| operator !=(Rectangle, Rectangle) | Compares two rectangles for inequality. |