Struct Rectangle
Describes a 2D-rectangle.
Implements
Namespace: Microsoft.Xna.Framework
Assembly: MonoGame.Framework.dll
Syntax
public struct Rectangle
Constructors
Rectangle(Point, Point)
Creates a new instance of Rectangle struct, with the specified location and size.
Declaration
public Rectangle(Point location, Point size)
Parameters
Type | Name | Description |
---|---|---|
Point | location | The x and y coordinates of the top-left corner of the created Rectangle. |
Point | size | The width and height of the created Rectangle. |
Rectangle(Int32, Int32, Int32, Int32)
Creates a new instance of Rectangle struct, with the specified position, width, and height.
Declaration
public Rectangle(int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | The x coordinate of the top-left corner of the created Rectangle. |
Int32 | y | The y coordinate of the top-left corner of the created Rectangle. |
Int32 | width | The width of the created Rectangle. |
Int32 | height | The height of the created Rectangle. |
Fields
Height
The height of this Rectangle.
Declaration
public int Height
Field Value
Type | Description |
---|---|
Int32 |
Width
The width of this Rectangle.
Declaration
public int Width
Field Value
Type | Description |
---|---|
Int32 |
X
The x coordinate of the top-left corner of this Rectangle.
Declaration
public int X
Field Value
Type | Description |
---|---|
Int32 |
Y
The y coordinate of the top-left corner of this Rectangle.
Declaration
public int Y
Field Value
Type | Description |
---|---|
Int32 |
Properties
Bottom
Returns the y coordinate of the bottom edge of this Rectangle.
Declaration
public readonly int Bottom { get; }
Property Value
Type | Description |
---|---|
Int32 |
Center
Declaration
public readonly Point Center { get; }
Property Value
Type | Description |
---|---|
Point |
Remarks
Empty
Returns a Rectangle with X=0, Y=0, Width=0, Height=0.
Declaration
public static readonly Rectangle Empty { get; }
Property Value
Type | Description |
---|---|
Rectangle |
IsEmpty
Declaration
public readonly bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
Boolean |
Left
Returns the x coordinate of the left edge of this Rectangle.
Declaration
public readonly int Left { get; }
Property Value
Type | Description |
---|---|
Int32 |
Location
The top-left coordinates of this Rectangle.
Declaration
public Point Location { get; set; }
Property Value
Type | Description |
---|---|
Point |
Right
Returns the x coordinate of the right edge of this Rectangle.
Declaration
public readonly int Right { get; }
Property Value
Type | Description |
---|---|
Int32 |
Size
The width-height coordinates of this Rectangle.
Declaration
public Point Size { get; set; }
Property Value
Type | Description |
---|---|
Point |
Top
Returns the y coordinate of the top edge of this Rectangle.
Declaration
public readonly int Top { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Contains(Point)
Declaration
public bool Contains(Point value)
Parameters
Type | Name | Description |
---|---|---|
Point | value | The coordinates to check for inclusion in this Rectangle. |
Returns
Type | Description |
---|---|
Boolean |
|
Contains(ref Point, out Boolean)
Declaration
public void Contains(ref Point value, out bool result)
Parameters
Type | Name | Description |
---|---|---|
Point | value | The coordinates to check for inclusion in this Rectangle. |
Boolean | result |
|
Contains(Rectangle)
Declaration
public bool Contains(Rectangle value)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | value |
Returns
Type | Description |
---|---|
Boolean |
|
Contains(ref Rectangle, out Boolean)
Declaration
public void Contains(ref Rectangle value, out bool result)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | value | |
Boolean | result |
|
Contains(Vector2)
Declaration
public bool Contains(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The coordinates to check for inclusion in this Rectangle. |
Returns
Type | Description |
---|---|
Boolean |
|
Contains(ref Vector2, out Boolean)
Declaration
public void Contains(ref Vector2 value, out bool result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The coordinates to check for inclusion in this Rectangle. |
Boolean | result |
|
Contains(Int32, Int32)
Gets whether or not the provided coordinates lie within the bounds of this Rectangle.
Declaration
public bool Contains(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | The x coordinate of the point to check for containment. |
Int32 | y | The y coordinate of the point to check for containment. |
Returns
Type | Description |
---|---|
Boolean |
|
Contains(Single, Single)
Gets whether or not the provided coordinates lie within the bounds of this Rectangle.
Declaration
public bool Contains(float x, float y)
Parameters
Type | Name | Description |
---|---|---|
Single | x | The x coordinate of the point to check for containment. |
Single | y | The y coordinate of the point to check for containment. |
Returns
Type | Description |
---|---|
Boolean |
|
Deconstruct(out Int32, out Int32, out Int32, out Int32)
Deconstruction method for Rectangle.
Declaration
public void Deconstruct(out int x, out int y, out int width, out int height)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | |
Int32 | y | |
Int32 | width | |
Int32 | height |
Equals(Rectangle)
Compares whether current instance is equal to specified Rectangle.
Declaration
public bool Equals(Rectangle other)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | other | The Rectangle to compare. |
Returns
Type | Description |
---|---|
Boolean |
|
Equals(Object)
Compares whether current instance is equal to specified
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The |
Returns
Type | Description |
---|---|
Boolean |
|
GetHashCode()
Gets the hash code of this Rectangle.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | Hash code of this Rectangle. |
Inflate(Int32, Int32)
Adjusts the edges of this Rectangle by specified horizontal and vertical amounts.
Declaration
public void Inflate(int horizontalAmount, int verticalAmount)
Parameters
Type | Name | Description |
---|---|---|
Int32 | horizontalAmount | Value to adjust the left and right edges. |
Int32 | verticalAmount | Value to adjust the top and bottom edges. |
Inflate(Single, Single)
Adjusts the edges of this Rectangle by specified horizontal and vertical amounts.
Declaration
public void Inflate(float horizontalAmount, float verticalAmount)
Parameters
Type | Name | Description |
---|---|---|
Single | horizontalAmount | Value to adjust the left and right edges. |
Single | verticalAmount | Value to adjust the top and bottom edges. |
Intersect(Rectangle, Rectangle)
Creates a new Rectangle that contains overlapping region of two other rectangles.
Declaration
public static Rectangle Intersect(Rectangle value1, Rectangle value2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | value1 | The first Rectangle. |
Rectangle | value2 | The second Rectangle. |
Returns
Type | Description |
---|---|
Rectangle | Overlapping region of the two rectangles. |
Intersect(ref Rectangle, ref Rectangle, out Rectangle)
Creates a new Rectangle that contains overlapping region of two other rectangles.
Declaration
public static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | value1 | The first Rectangle. |
Rectangle | value2 | The second Rectangle. |
Rectangle | result | Overlapping region of the two rectangles as an output parameter. |
Intersects(Rectangle)
Gets whether or not the other Rectangle intersects with this rectangle.
Declaration
public bool Intersects(Rectangle value)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | value | The other rectangle for testing. |
Returns
Type | Description |
---|---|
Boolean |
|
Intersects(ref Rectangle, out Boolean)
Gets whether or not the other Rectangle intersects with this rectangle.
Declaration
public void Intersects(ref Rectangle value, out bool result)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | value | The other rectangle for testing. |
Boolean | result |
|
Offset(Point)
Declaration
public void Offset(Point amount)
Parameters
Type | Name | Description |
---|---|---|
Point | amount | The x and y components to add to this Rectangle. |
Offset(Vector2)
Declaration
public void Offset(Vector2 amount)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | amount | The x and y components to add to this Rectangle. |
Offset(Int32, Int32)
Declaration
public void Offset(int offsetX, int offsetY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | offsetX | The x coordinate to add to this Rectangle. |
Int32 | offsetY | The y coordinate to add to this Rectangle. |
Offset(Single, Single)
Declaration
public void Offset(float offsetX, float offsetY)
Parameters
Type | Name | Description |
---|---|---|
Single | offsetX | The x coordinate to add to this Rectangle. |
Single | offsetY | The y coordinate to add to this Rectangle. |
ToString()
Returns a
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Union(Rectangle, Rectangle)
Creates a new Rectangle that completely contains two other rectangles.
Declaration
public static Rectangle Union(Rectangle value1, Rectangle value2)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | value1 | The first Rectangle. |
Rectangle | value2 | The second Rectangle. |
Returns
Type | Description |
---|---|
Rectangle | The union of the two rectangles. |
Union(ref Rectangle, ref Rectangle, out Rectangle)
Creates a new Rectangle that completely contains two other rectangles.
Declaration
public static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | value1 | The first Rectangle. |
Rectangle | value2 | The second Rectangle. |
Rectangle | result | The union of the two rectangles as an output parameter. |
Operators
Equality(Rectangle, Rectangle)
Compares whether two Rectangle instances are equal.
Declaration
public static bool operator ==(Rectangle a, Rectangle b)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | a | Rectangle instance on the left of the equal sign. |
Rectangle | b | Rectangle instance on the right of the equal sign. |
Returns
Type | Description |
---|---|
Boolean |
|
Inequality(Rectangle, Rectangle)
Compares whether two Rectangle instances are not equal.
Declaration
public static bool operator !=(Rectangle a, Rectangle b)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | a | Rectangle instance on the left of the not equal sign. |
Rectangle | b | Rectangle instance on the right of the not equal sign. |
Returns
Type | Description |
---|---|
Boolean |
|