Table of Contents

Struct Rectangle

Namespace
BSGameLib.Game.Drawing
Assembly
BSGameLib.Game.dll

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

location Point
size Point

Rectangle(Point, Size)

Creates a rectangle at location with the width and height of size.

public Rectangle(Point location, Size size)

Parameters

location Point
size Size

Rectangle(Point, int, int)

Creates a rectangle at location with the given width and height.

public Rectangle(Point location, int width, int height)

Parameters

location Point
width int
height int

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

location Point
size Vector2

Rectangle(Rectangle)

Creates a copy of rectangle.

public Rectangle(Rectangle rectangle)

Parameters

rectangle Rectangle

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

x double
y double
width double
height double

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

x int
y int
size Point

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

x int
y int
size Size

Rectangle(int, int, int, int)

Creates a rectangle from its position and size.

public Rectangle(int x, int y, int width, int height)

Parameters

x int
y int
width int
height int

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

x int
y int
size Vector2

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

location Vector2
size Point

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

location Vector2
size Size

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

location Vector2
width int
height int

Rectangle(Vector2, Vector2)

Creates a rectangle from two vectors, truncating each component to a whole number.

public Rectangle(Vector2 location, Vector2 size)

Parameters

location Vector2
size Vector2

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

x float
y float
width float
height float

Fields

Empty

A rectangle at (0, 0) with no size.

public static readonly Rectangle Empty

Field Value

Rectangle

Properties

Bottom

The y coordinate just past the bottom edge, Y + Height.

public readonly int Bottom { get; }

Property Value

int

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

Vector2

Height

The height, from the top edge.

public int Height { readonly get; set; }

Property Value

int

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

bool

Left

The x coordinate of the left edge, the same as X.

public readonly int Left { get; }

Property Value

int

Location

The top left corner, (X, Y).

public readonly Point Location { get; }

Property Value

Point

Right

The x coordinate just past the right edge, X + Width.

public readonly int Right { get; }

Property Value

int

Size

The width and height, as a Size.

public readonly Size Size { get; }

Property Value

Size

Top

The y coordinate of the top edge, the same as Y.

public readonly int Top { get; }

Property Value

int

Width

The width, from the left edge.

public int Width { readonly get; set; }

Property Value

int

X

The x coordinate of the left edge.

public int X { readonly get; set; }

Property Value

int

Y

The y coordinate of the top edge.

public int Y { readonly get; set; }

Property Value

int

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

x int
y int

Returns

bool

Contains(Vector2)

Whether point, truncated to whole numbers, is inside, as Contains(int, int) decides.

public bool Contains(Vector2 point)

Parameters

point Vector2

Returns

bool

Equals(Rectangle)

Whether other has the same position and size.

public readonly bool Equals(Rectangle other)

Parameters

other Rectangle

Returns

bool

Equals(object)

Whether obj is a Rectangle with the same position and size.

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetHashCode()

Returns a hash code based on the four fields, consistent with Equals(object).

public override readonly int GetHashCode()

Returns

int

Intersects(Point)

Whether the point is inside: the same as Contains(int, int).

public readonly bool Intersects(Point point)

Parameters

point Point

Returns

bool

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

point Point
other Rectangle

Returns

bool

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

point Point
size Size

Returns

bool

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

point Point
radius int

Returns

bool

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

point Point
width int
height int

Returns

bool

Intersects(Rectangle)

Whether the two rectangles overlap. Rectangles that only touch along an edge do not overlap.

public readonly bool Intersects(Rectangle other)

Parameters

other Rectangle

Returns

bool

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

other Rectangle
size Size

Returns

bool

Intersects(Rectangle, int)

Whether this rectangle overlaps other grown by radius on every side.

public readonly bool Intersects(Rectangle other, int radius)

Parameters

other Rectangle
radius int

Returns

bool

Intersects(Vector2)

Whether the point, truncated to whole pixels, is inside: the same as Contains(Vector2).

public readonly bool Intersects(Vector2 point)

Parameters

point Vector2

Returns

bool

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

point Vector2
other Rectangle

Returns

bool

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

point Vector2
size Size

Returns

bool

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

point Vector2
radius int

Returns

bool

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

point Vector2
width int
height int

Returns

bool

ToString()

Returns the fields as text, such as X: 1, Y: 2, Width: 3, Height: 4.

public override readonly string ToString()

Returns

string

Operators

operator +(Rectangle, Point)

Moves a by b. The size is unchanged.

public static Rectangle operator +(Rectangle a, Point b)

Parameters

a Rectangle
b Point

Returns

Rectangle

operator +(Rectangle, Rectangle)

Adds each field of a and b.

public static Rectangle operator +(Rectangle a, Rectangle b)

Parameters

a Rectangle
b Rectangle

Returns

Rectangle

operator +(Rectangle, Vector2)

Moves a by b, truncated to whole pixels. The size is unchanged.

public static Rectangle operator +(Rectangle a, Vector2 b)

Parameters

a Rectangle
b Vector2

Returns

Rectangle

operator ==(Rectangle, Rectangle)

Whether the two rectangles have the same position and size.

public static bool operator ==(Rectangle a, Rectangle b)

Parameters

a Rectangle
b Rectangle

Returns

bool

operator !=(Rectangle, Rectangle)

Whether the two rectangles differ in position or size.

public static bool operator !=(Rectangle a, Rectangle b)

Parameters

a Rectangle
b Rectangle

Returns

bool

operator -(Rectangle, Rectangle)

Subtracts each field of b from those of a.

public static Rectangle operator -(Rectangle a, Rectangle b)

Parameters

a Rectangle
b Rectangle

Returns

Rectangle

operator -(Rectangle, Vector2)

Moves a by b negated, truncated to whole pixels. The size is unchanged.

public static Rectangle operator -(Rectangle a, Vector2 b)

Parameters

a Rectangle
b Vector2

Returns

Rectangle