Struct Rectangle
Describes a 2D-rectangle.
[DataContract]
public struct Rectangle : IEquatable<Rectangle>
- Implements
- Inherited Members
Constructors
Rectangle(Point, Point)
Creates a new instance of Rectangle struct, with the specified location and size.
public Rectangle(Point location, Point size)
Parameters
locationPointThe x and y coordinates of the top-left corner of the created Rectangle.
sizePointThe width and height of the created Rectangle.
Rectangle(int, int, int, int)
Creates a new instance of Rectangle struct, with the specified position, width, and height.
public Rectangle(int x, int y, int width, int height)
Parameters
xintThe x coordinate of the top-left corner of the created Rectangle.
yintThe y coordinate of the top-left corner of the created Rectangle.
widthintThe width of the created Rectangle.
heightintThe height of the created Rectangle.
Fields
Height
The height of this Rectangle.
[DataMember]
public int Height
Field Value
Width
The width of this Rectangle.
[DataMember]
public int Width
Field Value
X
The x coordinate of the top-left corner of this Rectangle.
[DataMember]
public int X
Field Value
Y
The y coordinate of the top-left corner of this Rectangle.
[DataMember]
public int Y
Field Value
Properties
Bottom
Returns the y coordinate of the bottom edge of this Rectangle.
public int Bottom { get; }
Property Value
Center
public Point Center { get; }
Property Value
Remarks
Empty
Returns a Rectangle with X=0, Y=0, Width=0, Height=0.
public static Rectangle Empty { get; }
Property Value
IsEmpty
public bool IsEmpty { get; }
Property Value
Left
Returns the x coordinate of the left edge of this Rectangle.
public int Left { get; }
Property Value
Location
The top-left coordinates of this Rectangle.
public Point Location { get; set; }
Property Value
Right
Returns the x coordinate of the right edge of this Rectangle.
public int Right { get; }
Property Value
Size
The width-height coordinates of this Rectangle.
public Point Size { get; set; }
Property Value
Top
Returns the y coordinate of the top edge of this Rectangle.
public int Top { get; }
Property Value
Methods
Contains(Point)
public bool Contains(Point value)
Parameters
Returns
Contains(ref Point, out bool)
public void Contains(ref Point value, out bool result)
Parameters
valuePointThe coordinates to check for inclusion in this Rectangle.
resultbooltrueif the provided Point lies inside this Rectangle;falseotherwise. As an output parameter.
Contains(Rectangle)
public bool Contains(Rectangle value)
Parameters
Returns
Contains(ref Rectangle, out bool)
public void Contains(ref Rectangle value, out bool result)
Parameters
valueRectangleresultbooltrueif the provided Rectangle's bounds lie entirely inside this Rectangle;falseotherwise. As an output parameter.
Contains(Vector2)
public bool Contains(Vector2 value)
Parameters
Returns
Contains(ref Vector2, out bool)
public void Contains(ref Vector2 value, out bool result)
Parameters
valueVector2The coordinates to check for inclusion in this Rectangle.
resultbooltrueif the provided Vector2 lies inside this Rectangle;falseotherwise. As an output parameter.
Contains(int, int)
Gets whether or not the provided coordinates lie within the bounds of this Rectangle.
public bool Contains(int x, int y)
Parameters
xintThe x coordinate of the point to check for containment.
yintThe y coordinate of the point to check for containment.
Returns
Contains(float, float)
Gets whether or not the provided coordinates lie within the bounds of this Rectangle.
public bool Contains(float x, float y)
Parameters
xfloatThe x coordinate of the point to check for containment.
yfloatThe y coordinate of the point to check for containment.
Returns
Deconstruct(out int, out int, out int, out int)
Deconstruction method for Rectangle.
public void Deconstruct(out int x, out int y, out int width, out int height)
Parameters
Equals(Rectangle)
Compares whether current instance is equal to specified Rectangle.
public bool Equals(Rectangle other)
Parameters
Returns
- bool
trueif the instances are equal;falseotherwise.
Equals(object)
Compares whether current instance is equal to specified object.
public override bool Equals(object obj)
Parameters
Returns
- bool
trueif the instances are equal;falseotherwise.
GetHashCode()
Gets the hash code of this Rectangle.
public override int GetHashCode()
Returns
Inflate(int, int)
Adjusts the edges of this Rectangle by specified horizontal and vertical amounts.
public void Inflate(int horizontalAmount, int verticalAmount)
Parameters
horizontalAmountintValue to adjust the left and right edges.
verticalAmountintValue to adjust the top and bottom edges.
Inflate(float, float)
Adjusts the edges of this Rectangle by specified horizontal and vertical amounts.
public void Inflate(float horizontalAmount, float verticalAmount)
Parameters
horizontalAmountfloatValue to adjust the left and right edges.
verticalAmountfloatValue to adjust the top and bottom edges.
Intersect(Rectangle, Rectangle)
Creates a new Rectangle that contains overlapping region of two other rectangles.
public static Rectangle Intersect(Rectangle value1, Rectangle value2)
Parameters
Returns
- 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.
public static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
Parameters
value1RectangleThe first Rectangle.
value2RectangleThe second Rectangle.
resultRectangleOverlapping region of the two rectangles as an output parameter.
Intersects(Rectangle)
Gets whether or not the other Rectangle intersects with this rectangle.
public bool Intersects(Rectangle value)
Parameters
valueRectangleThe other rectangle for testing.
Returns
Intersects(ref Rectangle, out bool)
Gets whether or not the other Rectangle intersects with this rectangle.
public void Intersects(ref Rectangle value, out bool result)
Parameters
valueRectangleThe other rectangle for testing.
resultbooltrueif other Rectangle intersects with this rectangle;falseotherwise. As an output parameter.
Offset(Point)
public void Offset(Point amount)
Parameters
Offset(Vector2)
public void Offset(Vector2 amount)
Parameters
Offset(int, int)
public void Offset(int offsetX, int offsetY)
Parameters
offsetXintThe x coordinate to add to this Rectangle.
offsetYintThe y coordinate to add to this Rectangle.
Offset(float, float)
public void Offset(float offsetX, float offsetY)
Parameters
offsetXfloatThe x coordinate to add to this Rectangle.
offsetYfloatThe y coordinate to add to this Rectangle.
ToString()
Returns a string representation of this Rectangle in the format: {X:[X] Y:[Y] Width:[Width] Height:[Height]}
public override string ToString()
Returns
Union(Rectangle, Rectangle)
Creates a new Rectangle that completely contains two other rectangles.
public static Rectangle Union(Rectangle value1, Rectangle value2)
Parameters
Returns
- Rectangle
The union of the two rectangles.
Union(ref Rectangle, ref Rectangle, out Rectangle)
Creates a new Rectangle that completely contains two other rectangles.
public static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
Parameters
value1RectangleThe first Rectangle.
value2RectangleThe second Rectangle.
resultRectangleThe union of the two rectangles as an output parameter.
Operators
operator ==(Rectangle, Rectangle)
Compares whether two Rectangle instances are equal.
public static bool operator ==(Rectangle a, Rectangle b)
Parameters
aRectangleRectangle instance on the left of the equal sign.
bRectangleRectangle instance on the right of the equal sign.
Returns
- bool
trueif the instances are equal;falseotherwise.
operator !=(Rectangle, Rectangle)
Compares whether two Rectangle instances are not equal.
public static bool operator !=(Rectangle a, Rectangle b)
Parameters
aRectangleRectangle instance on the left of the not equal sign.
bRectangleRectangle instance on the right of the not equal sign.
Returns
- bool
trueif the instances are not equal;falseotherwise.