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
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
xintThe X coordinate of the top-left corner.
yintThe Y coordinate of the top-left corner.
widthintThe width of the rectangle.
heightintThe height of the rectangle.
Properties
Area
Gets the area of the rectangle.
public int Area { get; }
Property Value
Bottom
Gets the Y coordinate of the bottom edge of the rectangle.
public int Bottom { get; }
Property Value
Center
Gets the center point of the rectangle.
public Position Center { get; }
Property Value
Empty
Gets an empty rectangle at origin.
public static Rectangle Empty { get; }
Property Value
Height
The height of the rectangle.
public int Height { get; }
Property Value
IsEmpty
Gets whether the rectangle is empty (has zero or negative area).
public bool IsEmpty { get; }
Property Value
Left
Gets the X coordinate of the left edge of the rectangle.
public int Left { get; }
Property Value
Right
Gets the X coordinate of the right edge of the rectangle.
public int Right { get; }
Property Value
Top
Gets the Y coordinate of the top edge of the rectangle.
public int Top { get; }
Property Value
Width
The width of the rectangle.
public int Width { get; }
Property Value
X
The X coordinate of the rectangle's top-left corner.
public int X { get; }
Property Value
Y
The Y coordinate of the rectangle's top-left corner.
public int Y { get; }
Property Value
Methods
Contains(Position)
Determines whether the specified point is contained within this rectangle.
public bool Contains(Position point)
Parameters
pointPositionThe 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
otherRectangleThe 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
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
otherRectangleThe 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
objobjectThe 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
Returns
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
Returns
- Rectangle
The inflated rectangle.
Intersect(Rectangle)
Returns the intersection of this rectangle with another rectangle.
public Rectangle Intersect(Rectangle other)
Parameters
otherRectangleThe 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
otherRectangleThe 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
offsetPositionThe 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
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
otherRectangleThe 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
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
Returns
- bool
True if the rectangles are not equal; otherwise, false.