Struct Rectangle
A rectangle with its top left corner at (X, Y) and its size in Width and Height. Its right and bottom edges are at X + Width and Y + Height.
public struct Rectangle : IEquatable<Rectangle>
- Implements
- Inherited Members
- Extension Methods
Constructors
Rectangle(Point, Point)
Creates a rectangle at location whose width and height are the X and Y of size.
public Rectangle(Point location, Point size)
Parameters
Rectangle(Point, Size)
Creates a rectangle at location with the width and height of size.
public Rectangle(Point location, Size size)
Parameters
Rectangle(Point, int, int)
Creates a rectangle at location with the given width and height.
public Rectangle(Point location, int width, int height)
Parameters
Rectangle(Point, Vector2)
Creates a rectangle at location whose width and height are the components of size, truncated to whole numbers.
public Rectangle(Point location, Vector2 size)
Parameters
Rectangle(Rectangle)
Creates a copy of rectangle.
public Rectangle(Rectangle rectangle)
Parameters
rectangleRectangle
Rectangle(double, double, double, double)
Creates a rectangle, truncating each value to a whole number.
public Rectangle(double x, double y, double width, double height)
Parameters
Rectangle(int, int, Point)
Creates a rectangle at (x, y) whose width and height are the X and Y of size.
public Rectangle(int x, int y, Point size)
Parameters
Rectangle(int, int, Size)
Creates a rectangle at (x, y) with the width and height of size.
public Rectangle(int x, int y, Size size)
Parameters
Rectangle(int, int, int, int)
Creates a rectangle from its position and size.
public Rectangle(int x, int y, int width, int height)
Parameters
Rectangle(int, int, Vector2)
Creates a rectangle at (x, y) whose width and height are the components of size, truncated to whole numbers.
public Rectangle(int x, int y, Vector2 size)
Parameters
Rectangle(Vector2, Point)
Creates a rectangle at location whose width and height are the X and Y of size, truncated to whole numbers.
public Rectangle(Vector2 location, Point size)
Parameters
Rectangle(Vector2, Size)
Creates a rectangle at location with the width and height of size, both truncated to whole numbers.
public Rectangle(Vector2 location, Size size)
Parameters
Rectangle(Vector2, int, int)
Creates a rectangle at location with the given width and height, the position truncated to whole numbers.
public Rectangle(Vector2 location, int width, int height)
Parameters
Rectangle(Vector2, Vector2)
Creates a rectangle from two vectors, truncating each component to a whole number.
public Rectangle(Vector2 location, Vector2 size)
Parameters
Rectangle(float, float, float, float)
Creates a rectangle, truncating each value to a whole number.
public Rectangle(float x, float y, float width, float height)
Parameters
Fields
Empty
A rectangle at (0, 0) with no size.
public static readonly Rectangle Empty
Field Value
Properties
Bottom
The y coordinate just past the bottom edge, Y + Height.
public readonly int Bottom { get; }
Property Value
Center
The centre of the rectangle. It is worked out in whole pixels, so an odd Width or Height is rounded down before halving.
public readonly Vector2 Center { get; }
Property Value
Height
The height, from the top edge.
public int Height { readonly get; set; }
Property Value
IsEmpty
Whether all four fields are zero. A rectangle with no size at a non-zero position is not empty.
public readonly bool IsEmpty { get; }
Property Value
Left
The x coordinate of the left edge, the same as X.
public readonly int Left { get; }
Property Value
Location
public readonly Point Location { get; }
Property Value
Right
The x coordinate just past the right edge, X + Width.
public readonly int Right { get; }
Property Value
Size
The width and height, as a Size.
public readonly Size Size { get; }
Property Value
Top
The y coordinate of the top edge, the same as Y.
public readonly int Top { get; }
Property Value
Width
The width, from the left edge.
public int Width { readonly get; set; }
Property Value
X
The x coordinate of the left edge.
public int X { readonly get; set; }
Property Value
Y
The y coordinate of the top edge.
public int Y { readonly get; set; }
Property Value
Methods
Contains(int, int)
Whether the point (x, y) is inside. The rectangle covers
Width by Height pixels from (X, Y), so
X + Width and Y + Height are outside, as they are for Intersects(Rectangle).
public readonly bool Contains(int x, int y)
Parameters
Returns
Contains(Vector2)
Whether point, truncated to whole numbers, is inside, as Contains(int, int) decides.
public bool Contains(Vector2 point)
Parameters
pointVector2
Returns
Equals(Rectangle)
Whether other has the same position and size.
public readonly bool Equals(Rectangle other)
Parameters
otherRectangle
Returns
Equals(object)
Whether obj is a Rectangle with the same position and size.
public override bool Equals(object obj)
Parameters
objobject
Returns
GetHashCode()
Returns a hash code based on the four fields, consistent with Equals(object).
public override readonly int GetHashCode()
Returns
Intersects(Point)
Whether the point is inside: the same as Contains(int, int).
public readonly bool Intersects(Point point)
Parameters
pointPoint
Returns
Intersects(Point, Rectangle)
Whether a rectangle with its top left corner at point and the width and height of other overlaps this one. The position of other is not used.
public readonly bool Intersects(Point point, Rectangle other)
Parameters
Returns
Intersects(Point, Size)
Whether a rectangle with its top left corner at point and the given size overlaps this one.
public readonly bool Intersects(Point point, Size size)
Parameters
Returns
Intersects(Point, int)
Whether a square with sides of 2 * radius, centred on point, overlaps the rectangle.
public readonly bool Intersects(Point point, int radius)
Parameters
Returns
Intersects(Point, int, int)
Whether a rectangle with its top left corner at point and the given width and height overlaps this one.
public readonly bool Intersects(Point point, int width, int height)
Parameters
Returns
Intersects(Rectangle)
Whether the two rectangles overlap. Rectangles that only touch along an edge do not overlap.
public readonly bool Intersects(Rectangle other)
Parameters
otherRectangle
Returns
Intersects(Rectangle, Size)
Whether this rectangle overlaps a rectangle with its top left corner at the position of other and the given size. The size of other is not used.
public readonly bool Intersects(Rectangle other, Size size)
Parameters
Returns
Intersects(Rectangle, int)
Whether this rectangle overlaps other grown by radius on every side.
public readonly bool Intersects(Rectangle other, int radius)
Parameters
Returns
Intersects(Vector2)
Whether the point, truncated to whole pixels, is inside: the same as Contains(Vector2).
public readonly bool Intersects(Vector2 point)
Parameters
pointVector2
Returns
Intersects(Vector2, Rectangle)
Whether a rectangle with its top left corner at point and the width and height of other overlaps this one. The position of other is not used.
public readonly bool Intersects(Vector2 point, Rectangle other)
Parameters
Returns
Intersects(Vector2, Size)
Whether a rectangle with its top left corner at point and the given size overlaps this one.
public readonly bool Intersects(Vector2 point, Size size)
Parameters
Returns
Intersects(Vector2, int)
Whether a square with sides of 2 * radius, centred on point, overlaps the rectangle. The right and bottom edges are not counted in the overlap.
public readonly bool Intersects(Vector2 point, int radius)
Parameters
Returns
Intersects(Vector2, int, int)
Whether a rectangle with its top left corner at point and the given width and height overlaps this one.
public readonly bool Intersects(Vector2 point, int width, int height)
Parameters
Returns
ToString()
Returns the fields as text, such as X: 1, Y: 2, Width: 3, Height: 4.
public override readonly string ToString()
Returns
Operators
operator +(Rectangle, Point)
Moves a by b. The size is unchanged.
public static Rectangle operator +(Rectangle a, Point b)
Parameters
Returns
operator +(Rectangle, Rectangle)
Adds each field of a and b.
public static Rectangle operator +(Rectangle a, Rectangle b)
Parameters
Returns
operator +(Rectangle, Vector2)
Moves a by b, truncated to whole pixels. The size is unchanged.
public static Rectangle operator +(Rectangle a, Vector2 b)
Parameters
Returns
operator ==(Rectangle, Rectangle)
Whether the two rectangles have the same position and size.
public static bool operator ==(Rectangle a, Rectangle b)
Parameters
Returns
operator !=(Rectangle, Rectangle)
Whether the two rectangles differ in position or size.
public static bool operator !=(Rectangle a, Rectangle b)
Parameters
Returns
operator -(Rectangle, Rectangle)
Subtracts each field of b from those of a.
public static Rectangle operator -(Rectangle a, Rectangle b)
Parameters
Returns
operator -(Rectangle, Vector2)
Moves a by b negated, truncated to whole pixels. The size is unchanged.
public static Rectangle operator -(Rectangle a, Vector2 b)