Table of Contents

Struct Rectangle

Namespace
SimulationFramework
Assembly
SimulationFramework.dll

An axis-aligned floating-point rectangle consisting of a position and size.

public struct Rectangle : IEquatable<Rectangle>
Implements
Inherited Members
Extension Methods

Constructors

Rectangle(Vector2, Vector2, Alignment)

Creates a new rectangle from the provided position and size.

public Rectangle(Vector2 position, Vector2 size, Alignment alignment = Alignment.TopLeft)

Parameters

position Vector2

The position of the rectangle.

size Vector2

The size of the rectangle.

alignment Alignment

The relative location of position on the rectangle.

Rectangle(float, float, float, float, Alignment)

Creates a new rectangle from the provided position and size.

public Rectangle(float x, float y, float width, float height, Alignment alignment = Alignment.TopLeft)

Parameters

x float

The x-coordinate of the position of the rectangle.

y float

The y-coordinate of the position of the rectangle.

width float

The width of the rectangle.

height float

The height of the rectangle.

alignment Alignment

The relative location of (x, y) on the rectangle.

Fields

Height

The height of the rectangle.

public float Height

Field Value

float

Width

The width of the rectangle.

public float Width

Field Value

float

X

The x-coordinate of the top-left corner of the rectangle.

public float X

Field Value

float

Y

The y-coordinate of the top-left corner of the rectangle.

public float Y

Field Value

float

Properties

Center

The center of the rectangle.

public Vector2 Center { readonly get; set; }

Property Value

Vector2

Position

The top-left corner of the rectangle.

public Vector2 Position { readonly get; set; }

Property Value

Vector2

Size

The size of the rectangle.

public Vector2 Size { readonly get; set; }

Property Value

Vector2

Methods

ContainsPoint(Vector2)

Determines if the rectangle contains the provided point.

public bool ContainsPoint(Vector2 point)

Parameters

point Vector2

The point to check the rectangle for.

Returns

bool

true if the rectangle contains point; otherwise false.

Equals(Rectangle)

Indicates if this rectangle is equal to another.

public readonly bool Equals(Rectangle other)

Parameters

other Rectangle

The rectangle to compare against this one.

Returns

bool

true if this rectangle equals other, otherwise false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

FromLTRB(float, float, float, float)

Creates a rectangle given the absolute position of each of its sides.

public static Rectangle FromLTRB(float left, float top, float right, float bottom)

Parameters

left float

The position of the left side of the rectangle on the x-axis.

top float

The position of the top of the rectangle on the y-axis.

right float

The position of the right side of the rectangle on the x-axis.

bottom float

The position of the bottom of the rectangle on the y-axis.

Returns

Rectangle

FromPoints(Vector2, Vector2)

Creates the smallest possible rectangle that contains a pair of points.

public static Rectangle FromPoints(Vector2 a, Vector2 b)

Parameters

a Vector2

The first point.

b Vector2

The second point.

Returns

Rectangle

GetAlignedPoint(Alignment)

Returns the point which aligned to the rectangle by the specified alignment.

public readonly Vector2 GetAlignedPoint(Alignment alignment)

Parameters

alignment Alignment

Returns

Vector2

GetHashCode()

Returns the hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Intersects(Rectangle)

Determines if the rectangle has an intersection with another.

public bool Intersects(Rectangle other)

Parameters

other Rectangle

The rectangle to check for an intersection with.

Returns

bool

true if the rectangles are intersecting; otherwise false.

Intersects(Rectangle, out Rectangle)

Determines if the rectangle has any intersection with another.

public bool Intersects(Rectangle other, out Rectangle overlap)

Parameters

other Rectangle

The rectangle to check for an intersection with.

overlap Rectangle

The overlapping area between the two rectangles.

Returns

bool

true if the rectangles are intersecting; otherwise false.

SetAlignedPosition(Vector2, Alignment)

Moves the rectangle such that the provided point is at the specified position.

public void SetAlignedPosition(Vector2 position, Alignment alignment)

Parameters

position Vector2

The position to align to.

alignment Alignment

The point on the rectangle to align to position.

ToString()

Returns this rectangle in the format "{x, y, width, height}".

public override readonly string ToString()

Returns

string

Union(Rectangle)

Returns the smallest rectangle that contains both this rectangle and another.

public readonly Rectangle Union(Rectangle other)

Parameters

other Rectangle

Returns

Rectangle

Operators

operator ==(Rectangle, Rectangle)

Indicates if two rectangles are equal.

public static bool operator ==(Rectangle left, Rectangle right)

Parameters

left Rectangle

The first rectangle.

right Rectangle

The second rectangle.

Returns

bool

true if the rectangles are equal, otherwise false.

operator !=(Rectangle, Rectangle)

Indicates if two rectangles are not equal.

public static bool operator !=(Rectangle left, Rectangle right)

Parameters

left Rectangle

The first rectangle.

right Rectangle

The second rectangle.

Returns

bool

true if the rectangles are not equal, otherwise false.