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
location
PointThe x and y coordinates of the top-left corner of the created Rectangle.
size
PointThe 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
x
intThe x coordinate of the top-left corner of the created Rectangle.
y
intThe y coordinate of the top-left corner of the created Rectangle.
width
intThe width of the created Rectangle.
height
intThe 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
value
PointThe coordinates to check for inclusion in this Rectangle.
result
booltrue
if the provided Point lies inside this Rectangle;false
otherwise. 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
value
Rectangleresult
booltrue
if the provided Rectangle's bounds lie entirely inside this Rectangle;false
otherwise. 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
value
Vector2The coordinates to check for inclusion in this Rectangle.
result
booltrue
if the provided Vector2 lies inside this Rectangle;false
otherwise. 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
x
intThe x coordinate of the point to check for containment.
y
intThe 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
x
floatThe x coordinate of the point to check for containment.
y
floatThe 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
true
if the instances are equal;false
otherwise.
Equals(object)
Compares whether current instance is equal to specified object.
public override bool Equals(object obj)
Parameters
Returns
- bool
true
if the instances are equal;false
otherwise.
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
horizontalAmount
intValue to adjust the left and right edges.
verticalAmount
intValue 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
horizontalAmount
floatValue to adjust the left and right edges.
verticalAmount
floatValue 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
value1
RectangleThe first Rectangle.
value2
RectangleThe second Rectangle.
result
RectangleOverlapping 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
value
RectangleThe 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
value
RectangleThe other rectangle for testing.
result
booltrue
if other Rectangle intersects with this rectangle;false
otherwise. 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
offsetX
intThe x coordinate to add to this Rectangle.
offsetY
intThe y coordinate to add to this Rectangle.
Offset(float, float)
public void Offset(float offsetX, float offsetY)
Parameters
offsetX
floatThe x coordinate to add to this Rectangle.
offsetY
floatThe 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
value1
RectangleThe first Rectangle.
value2
RectangleThe second Rectangle.
result
RectangleThe 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
a
RectangleRectangle instance on the left of the equal sign.
b
RectangleRectangle instance on the right of the equal sign.
Returns
- bool
true
if the instances are equal;false
otherwise.
operator !=(Rectangle, Rectangle)
Compares whether two Rectangle instances are not equal.
public static bool operator !=(Rectangle a, Rectangle b)
Parameters
a
RectangleRectangle instance on the left of the not equal sign.
b
RectangleRectangle instance on the right of the not equal sign.
Returns
- bool
true
if the instances are not equal;false
otherwise.