Rect
Struct · namespace System.Drawing · Since 0.45
struct Rect : IEquatable<Rect>, IHashableA rectangle in pixels: X and Y are its top left corner. The right and bottom edges are outside: the rectangle
covers the columns X to X + Width - 1.
Fields
Section titled “Fields”| Name | Description |
|---|---|
X |
The left edge. |
Y |
The top edge. |
Width |
The width in pixels. |
Height |
The height in pixels. |
int XThe left edge.
int YThe top edge.
int WidthThe width in pixels.
Height
Section titled “Height”int HeightThe height in pixels.
Static methods
Section titled “Static methods”| Name | Description |
|---|---|
Create |
A rectangle with its top left corner at (x, y). |
FromEdges |
The rectangle from (left, top) to (right, bottom), which are outside. |
Create
Section titled “Create”static Rect Create(int x, int y, int width, int height)A rectangle with its top left corner at (x, y).
static Rect Create(Point position, Size size)A rectangle with its top left corner at position.
FromEdges
Section titled “FromEdges”static Rect FromEdges(int left, int top, int right, int bottom)The rectangle from (left, top) to (right, bottom), which are outside.
Methods
Section titled “Methods”| Name | Description |
|---|---|
Right |
The first column to the right of the rectangle. |
Bottom |
The first row below the rectangle. |
Position |
The top left corner. |
Size |
The width and the height. |
Center |
The center (rounded down). |
Contains |
True if the point lies inside (the right and bottom edges are outside). |
Intersects |
True if both rectangles share at least one pixel (a collision of two sprites). |
Intersect |
The part that both rectangles cover (empty if they do not overlap). |
Union |
The smallest rectangle that covers both (an empty one does not count). |
Offset |
The rectangle moved by (dx, dy). |
Shrink |
The rectangle made smaller by amount on every side (larger for a negative amount). |
IsEmpty |
True if it covers no pixel. |
Equals |
True if both have the same position and size. |
GetHashCode |
A hash code of the position and the size. |
ToString |
“(x, y, width x height)”. |
int Right()The first column to the right of the rectangle.
Bottom
Section titled “Bottom”int Bottom()The first row below the rectangle.
Position
Section titled “Position”Point Position()The top left corner.
Size Size()The width and the height.
Center
Section titled “Center”Point Center()The center (rounded down).
Contains
Section titled “Contains”bool Contains(int x, int y)True if the point lies inside (the right and bottom edges are outside).
bool Contains(Point point)True if the point lies inside (the right and bottom edges are outside).
bool Contains(Rect other)True if other lies completely inside.
Intersects
Section titled “Intersects”bool Intersects(Rect other)True if both rectangles share at least one pixel (a collision of two sprites).
Intersect
Section titled “Intersect”Rect Intersect(Rect other)The part that both rectangles cover (empty if they do not overlap).
Rect Union(Rect other)The smallest rectangle that covers both (an empty one does not count).
Offset
Section titled “Offset”Rect Offset(int dx, int dy)The rectangle moved by (dx, dy).
Rect Offset(Point delta)The rectangle moved by delta.
Shrink
Section titled “Shrink”Rect Shrink(int amount)The rectangle made smaller by amount on every side (larger for a negative amount).
IsEmpty
Section titled “IsEmpty”bool IsEmpty()True if it covers no pixel.
Equals
Section titled “Equals”bool Equals(Rect other)True if both have the same position and size.
GetHashCode
Section titled “GetHashCode”int GetHashCode()A hash code of the position and the size.
ToString
Section titled “ToString”string ToString()“(x, y, width x height)”.