Struct Rectangle
Stores a set of four integers that represent the location and size of a rectangle.
Implements
Inherited Members
Namespace: Evergine.Mathematics
Assembly: Evergine.Mathematics.dll
Syntax
public struct Rectangle : IEquatable<Rectangle>
Constructors
Rectangle(int, int, int, int)
Initializes a new instance of the Rectangle struct with the specified location and size.
Declaration
public Rectangle(int x, int y, int width, int height)
Parameters
Type | Name | Description |
---|---|---|
int | x | The x-coordinate of the upper-left corner of the rectangle. |
int | y | The y-coordinate of the upper-left corner of the rectangle. |
int | width | The width of the rectangle. |
int | height | The height of the rectangle. |
Fields
Height
Gets or sets the height of this Rectangle structure. The default is 0.
Declaration
public int Height
Field Value
Type | Description |
---|---|
int |
Width
Gets or sets the width of this Rectangle structure. The default is 0.
Declaration
public int Width
Field Value
Type | Description |
---|---|
int |
X
Gets or sets the x-coordinate of the upper-left corner of this Rectangle structure. The default is 0.
Declaration
public int X
Field Value
Type | Description |
---|---|
int |
Y
Gets or sets the y-coordinate of the upper-left corner of this Rectangle structure. The default is 0.
Declaration
public int Y
Field Value
Type | Description |
---|---|
int |
Properties
Bottom
Declaration
public int Bottom { get; }
Property Value
Type | Description |
---|---|
int |
Center
Gets the coordinates of the center of this Rectangle structure.
Declaration
public Point Center { get; }
Property Value
Type | Description |
---|---|
Point | A Point that represents the center of this Rectangle structure. |
Empty
Gets an instance of the Rectangle class with its members uninitialized.
Declaration
public static Rectangle Empty { get; }
Property Value
Type | Description |
---|---|
Rectangle |
Remarks
The members of the new Rectangle are left uninitialized.
IsEmpty
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool | .
This property returns |
Left
Gets the x-coordinate of the left edge of this Rectangle structure.
Declaration
public int Left { get; }
Property Value
Type | Description |
---|---|
int |
Location
Gets or sets the coordinates of the upper-left corner of this Rectangle structure.
Declaration
public Point Location { get; set; }
Property Value
Type | Description |
---|---|
Point | A Point that represents the upper-left corner of this Rectangle structure. |
Right
Declaration
public int Right { get; }
Property Value
Type | Description |
---|---|
int |
Top
Gets the y-coordinate of the top edge of this Rectangle structure.
Declaration
public int Top { get; }
Property Value
Type | Description |
---|---|
int |
Methods
Contains(Point)
Determines if the specified point is contained within this Rectangle structure.
Declaration
public bool Contains(Point pt)
Parameters
Type | Name | Description |
---|---|---|
Point | pt | The Point to test. |
Returns
Type | Description |
---|---|
bool | This method returns |
Contains(ref Point, out bool)
Determines if the specified point is contained within this Rectangle structure.
Declaration
public void Contains(ref Point pt, out bool result)
Parameters
Type | Name | Description |
---|---|---|
Point | pt | The Point to test. |
bool | result | if set to |
Contains(Rectangle)
Determines if the rectangular region represented by rect
is entirely contained
within this Rectangle structure.
Declaration
public bool Contains(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect | The Rectangle to test. |
Returns
Type | Description |
---|---|
bool | This method returns |
Contains(ref Rectangle, out bool)
Determines if the rectangular region represented by rect
is entirely contained
within this Rectangle structure.
Declaration
public void Contains(ref Rectangle rect, out bool result)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect | The Rectangle to test. |
bool | result | if set to |
Contains(int, int)
Determines if the specified point is contained within this Rectangle structure.
Declaration
public bool Contains(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
int | x | The x-coordinate of the point to test. |
int | y | The y-coordinate of the point to test. |
Returns
Type | Description |
---|---|
bool | This method returns |
Equals(Rectangle)
Tests whether other
has the same location and size of this Rectangle.
Declaration
public bool Equals(Rectangle other)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | other | The Rectangle to test. |
Returns
Type | Description |
---|---|
bool | This method returns |
Equals(ref Rectangle)
Equalses the specified other.
Declaration
public bool Equals(ref Rectangle other)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | other | The other. |
Returns
Type | Description |
---|---|
bool | The result. |
Equals(object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to test. |
Returns
Type | Description |
---|---|
bool | This method returns |
Overrides
GetHashCode()
Gets the hash code for this Rectangle structure. For information about the use of hash codes, see GetHashCode().
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
Overrides
Inflate(int, int)
Enlarges this Rectangle structure by the specified amount.
Declaration
public void Inflate(int horizontalAmount, int verticalAmount)
Parameters
Type | Name | Description |
---|---|---|
int | horizontalAmount | The amount to inflate this Rectangle structure horizontally. |
int | verticalAmount | The amount to inflate this Rectangle structure vertically. |
Remarks
This method enlarges this rectangle, not a copy of it. The rectangle is enlarged in both directions along an axis. For example, if a 50 by 50 rectangle is inflated by 50 in the x-axis, the resultant rectangle will be 150 units long (the original 50, the 50 in the minus direction, and the 50 in the plus direction) maintaining the rectangle's geometric center. If either x or y is negative, the Rectangle is deflated in the corresponding direction.
Intersect(Rectangle, Rectangle)
Returns a Rectangle structure that represents the intersection of two rectangles. If there is no intersection, and empty Rectangle is returned.
Declaration
public static Rectangle Intersect(Rectangle a, Rectangle b)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | a | A rectangle to intersect. |
Rectangle | b | The second rectangle to intersect. |
Returns
Type | Description |
---|---|
Rectangle | A third Rectangle structure the size of which represents the overlapped area of the two specified rectangles. |
Intersect(ref Rectangle, ref Rectangle, out Rectangle)
Calculates a Rectangle structure that represents the intersection of two rectangles. If there is no intersection, and empty Rectangle is returned.
Declaration
public static void Intersect(ref Rectangle a, ref Rectangle b, out Rectangle result)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | a | A rectangle to intersect. |
Rectangle | b | The second rectangle to intersect. |
Rectangle | result | A rectangle that represents the intersection of two rectangles. |
Intersects(Rectangle)
Determines if this rectangle intersects with rect
.
Declaration
public bool Intersects(Rectangle rect)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect | The rectangle to test. |
Returns
Type | Description |
---|---|
bool | This method returns |
Intersects(ref Rectangle, out bool)
Determines if this rectangle intersects with rect
.
Declaration
public void Intersects(ref Rectangle rect, out bool result)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | rect | The rectangle to test. |
bool | result | if set to |
Offset(Point)
Adjusts the location of this rectangle by the specified amount
.
Declaration
public void Offset(Point amount)
Parameters
Type | Name | Description |
---|---|---|
Point | amount | The amount to offset the location. |
Offset(int, int)
Adjusts the location of this rectangle by the specified amount.
Declaration
public void Offset(int offsetX, int offsetY)
Parameters
Type | Name | Description |
---|---|---|
int | offsetX | The amount to offset the location horizontally. |
int | offsetY | The amount to offset the location vertically. |
Round(RectangleF)
Converts the specified RectangleF to a Rectangle by rounding the RectangleF values to the nearest integer values.
Declaration
public static Rectangle Round(RectangleF value)
Parameters
Type | Name | Description |
---|---|---|
RectangleF | value | The Rectangle value. |
Returns
Type | Description |
---|---|
Rectangle | The rounded interger value of the Rectangle. |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that contains the position, width, and height of this Rectangle structure. For example, "{X:20, Y:20, Width:100, Height:50}". |
Overrides
ToVector4()
Declaration
public Vector4 ToVector4()
Returns
Type | Description |
---|---|
Vector4 | A Vector4 that contains the X, Y, Width, Height, of this Rectangle to a Vector4 structure. |
ToVector4(ref Vector4)
Declaration
public void ToVector4(ref Vector4 vector)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vector |
Truncate(RectangleF)
Converts the specified RectangleF to a Rectangle by truncating the RectangleF values.
Declaration
public static Rectangle Truncate(RectangleF value)
Parameters
Type | Name | Description |
---|---|---|
RectangleF | value | The RectangleF to be converted. |
Returns
Type | Description |
---|---|
Rectangle | The truncated value of the Rectangle. |
Union(Rectangle, Rectangle)
Creates the smallest possible third rectangle that can contain both of two rectangles that form a union.
Declaration
public static Rectangle Union(Rectangle a, Rectangle b)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | a | A rectangle to union. |
Rectangle | b | The second rectangle to union. |
Returns
Type | Description |
---|---|
Rectangle | A third Rectangle structure that contains both of the two rectangles that form the union. |
Union(ref Rectangle, ref Rectangle, out Rectangle)
Calculates the smallest possible third rectangle that can contain both of two rectangles that form a union.
Declaration
public static void Union(ref Rectangle a, ref Rectangle b, out Rectangle result)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | a | A rectangle to union. |
Rectangle | b | The second rectangle to union. |
Rectangle | result | The smallest possible third rectangle that can contain both of two rectangles that form a union. |
Operators
operator ==(Rectangle, Rectangle)
Tests whether two Rectangle structures have equal location and size.
Declaration
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | left | The Rectangle structure that is to the left of the inequality operator. |
Rectangle | right | The Rectangle structure that is to the right of the inequality operator. |
Returns
Type | Description |
---|---|
bool | This operator returns |
operator !=(Rectangle, Rectangle)
Tests whether two Rectangle structures differ in location or size.
Declaration
public static bool operator !=(Rectangle left, Rectangle right)
Parameters
Type | Name | Description |
---|---|---|
Rectangle | left | The Rectangle structure that is to the left of the inequality operator. |
Rectangle | right | The Rectangle structure that is to the right of the inequality operator. |
Returns
Type | Description |
---|---|
bool | This operator returns |