Table of Contents

Struct Rectangle

Namespace
Gloam.Core.Primitives
Assembly
Gloam.Core.dll

Represents a rectangle with integer coordinates optimized for roguelike grid-based operations. Follows KISS principles with minimal overhead and high performance for frequent allocations.

public readonly struct Rectangle : IEquatable<Rectangle>
Implements
Inherited Members

Constructors

Rectangle(Position, Size)

Initializes a new rectangle with the specified position and size.

public Rectangle(Position position, Size size)

Parameters

position Position

The top-left corner position.

size Size

The size of the rectangle.

Rectangle(int, int, int, int)

Initializes a new rectangle with the specified position and size.

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

Parameters

x int

The X coordinate of the top-left corner.

y int

The Y coordinate of the top-left corner.

width int

The width of the rectangle.

height int

The height of the rectangle.

Properties

Area

Gets the area of the rectangle.

public int Area { get; }

Property Value

int

Bottom

Gets the Y coordinate of the bottom edge of the rectangle.

public int Bottom { get; }

Property Value

int

Center

Gets the center point of the rectangle.

public Position Center { get; }

Property Value

Position

Empty

Gets an empty rectangle at origin.

public static Rectangle Empty { get; }

Property Value

Rectangle

Height

The height of the rectangle.

public int Height { get; }

Property Value

int

IsEmpty

Gets whether the rectangle is empty (has zero or negative area).

public bool IsEmpty { get; }

Property Value

bool

Left

Gets the X coordinate of the left edge of the rectangle.

public int Left { get; }

Property Value

int

Right

Gets the X coordinate of the right edge of the rectangle.

public int Right { get; }

Property Value

int

Top

Gets the Y coordinate of the top edge of the rectangle.

public int Top { get; }

Property Value

int

Width

The width of the rectangle.

public int Width { get; }

Property Value

int

X

The X coordinate of the rectangle's top-left corner.

public int X { get; }

Property Value

int

Y

The Y coordinate of the rectangle's top-left corner.

public int Y { get; }

Property Value

int

Methods

Contains(Position)

Determines whether the specified point is contained within this rectangle.

public bool Contains(Position point)

Parameters

point Position

The point to test.

Returns

bool

True if the point is contained within the rectangle; otherwise, false.

Contains(Rectangle)

Determines whether the specified rectangle is entirely contained within this rectangle.

public bool Contains(Rectangle other)

Parameters

other Rectangle

The rectangle to test.

Returns

bool

True if the rectangle is entirely contained; otherwise, false.

Contains(int, int)

Determines whether the specified point is contained within this rectangle.

public bool Contains(int x, int y)

Parameters

x int

The X coordinate of the point.

y int

The Y coordinate of the point.

Returns

bool

True if the point is contained within the rectangle; otherwise, false.

Equals(Rectangle)

Indicates whether this rectangle is equal to another rectangle.

public bool Equals(Rectangle other)

Parameters

other Rectangle

The rectangle to compare with.

Returns

bool

True if the rectangles are equal; otherwise, false.

Equals(object?)

Indicates whether this rectangle is equal to the specified object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with.

Returns

bool

True if the objects are equal; otherwise, false.

FromCorners(Position, Position)

Initializes a new rectangle from two corner points.

public static Rectangle FromCorners(Position topLeft, Position bottomRight)

Parameters

topLeft Position

The top-left corner.

bottomRight Position

The bottom-right corner.

Returns

Rectangle

GetHashCode()

Returns the hash code for this rectangle.

public override int GetHashCode()

Returns

int

A hash code for this rectangle.

Inflate(int, int)

Returns a new rectangle inflated by the specified amount.

public Rectangle Inflate(int width, int height)

Parameters

width int

The amount to inflate horizontally.

height int

The amount to inflate vertically.

Returns

Rectangle

The inflated rectangle.

Intersect(Rectangle)

Returns the intersection of this rectangle with another rectangle.

public Rectangle Intersect(Rectangle other)

Parameters

other Rectangle

The rectangle to intersect with.

Returns

Rectangle

The intersection rectangle, or Empty if no intersection exists.

Intersects(Rectangle)

Determines whether this rectangle intersects with another rectangle.

public bool Intersects(Rectangle other)

Parameters

other Rectangle

The rectangle to test for intersection.

Returns

bool

True if the rectangles intersect; otherwise, false.

Offset(Position)

Returns a new rectangle with the specified offset applied.

public Rectangle Offset(Position offset)

Parameters

offset Position

The offset point.

Returns

Rectangle

The offset rectangle.

Offset(int, int)

Returns a new rectangle with the specified offset applied.

public Rectangle Offset(int offsetX, int offsetY)

Parameters

offsetX int

The X offset.

offsetY int

The Y offset.

Returns

Rectangle

The offset rectangle.

ToString()

Returns a string representation of this rectangle.

public override string ToString()

Returns

string

A string representation of this rectangle.

Union(Rectangle)

Returns the union of this rectangle with another rectangle.

public Rectangle Union(Rectangle other)

Parameters

other Rectangle

The rectangle to union with.

Returns

Rectangle

The union rectangle.

Operators

operator ==(Rectangle, Rectangle)

Determines whether 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)

Determines whether 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.