Table of Contents

Struct Rect

Namespace
Xui.Core.Math2D
Assembly
Core.dll

Represents a rectangle in 2D space, defined by its origin (X, Y) and its dimensions (Width, Height).

public struct Rect : INonEnumerableSet<Point>
Implements
Inherited Members

Remarks

Unlike Frame, which represents edge thicknesses around a box, Rect defines a positioned, sized area used for layout and rendering.

Constructors

Rect(NFloat, NFloat, NFloat, NFloat)

Creates a new Rect from position and size.

public Rect(NFloat x, NFloat y, NFloat width, NFloat height)

Parameters

x NFloat
y NFloat
width NFloat
height NFloat

Rect(Point, Size)

Creates a new Rect from a top-left point and a size.

public Rect(Point topLeft, Size size)

Parameters

topLeft Point
size Size

Rect(Vector, Size)

Creates a new Rect from a top-left vector and a size.

public Rect(Vector topLeft, Size size)

Parameters

topLeft Vector
size Size

Fields

Height

The height of the rectangle.

public NFloat Height

Field Value

NFloat

Width

The width of the rectangle.

public NFloat Width

Field Value

NFloat

X

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

public NFloat X

Field Value

NFloat

Y

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

public NFloat Y

Field Value

NFloat

Properties

Bottom

Returns the Y-coordinate of the bottom edge.

public NFloat Bottom { get; }

Property Value

NFloat

BottomLeft

Returns the bottom-left point of the rectangle.

public Point BottomLeft { get; }

Property Value

Point

BottomRight

Returns the bottom-right point of the rectangle.

public Point BottomRight { get; }

Property Value

Point

Center

Returns the center point of the rectangle.

public Point Center { get; }

Property Value

Point

Left

Returns the X-coordinate of the left edge.

public NFloat Left { get; }

Property Value

NFloat

Right

Returns the X-coordinate of the right edge.

public NFloat Right { get; }

Property Value

NFloat

Size

Gets or sets the size of the rectangle.

public Size Size { get; set; }

Property Value

Size

Top

Returns the Y-coordinate of the top edge.

public NFloat Top { get; }

Property Value

NFloat

TopCenter

Returns the top-center point of the rectangle.

public Point TopCenter { get; }

Property Value

Point

TopLeft

Returns the top-left point of the rectangle.

public Point TopLeft { get; }

Property Value

Point

TopRight

Returns the top-right point of the rectangle.

public Point TopRight { get; }

Property Value

Point

Methods

Contains(Point)

Returns true if the specified point lies within this rectangle.

public bool Contains(Point point)

Parameters

point Point

Returns

bool

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override 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.

Equals(Rect)

Returns true if this rectangle is equal to another rectangle in position and size.

public bool Equals(Rect other)

Parameters

other Rect

Returns

bool

Expand(NFloat)

Returns a rectangle expanded uniformly in all directions.

public Rect Expand(NFloat expand)

Parameters

expand NFloat

Returns

Rect

Expand(NFloat, NFloat)

Returns a rectangle expanded horizontally and vertically by the specified amounts.

public Rect Expand(NFloat h, NFloat v)

Parameters

h NFloat
v NFloat

Returns

Rect

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

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

Inset(NFloat)

Returns a new rectangle that is inset by the same amount on all four sides.

public Rect Inset(NFloat inset)

Parameters

inset NFloat

Returns

Rect

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator +(Rect, Frame)

Returns a rectangle expanded outward by a Frame.

public static Rect operator +(Rect rect, Frame frame)

Parameters

rect Rect
frame Frame

Returns

Rect

operator ==(Rect, Rect)

Returns true if two rectangles are equal in position and size.

public static bool operator ==(Rect lhs, Rect rhs)

Parameters

lhs Rect
rhs Rect

Returns

bool

implicit operator Rect((NFloat, NFloat, NFloat, NFloat))

Implicit conversion from a 4-tuple to a rectangle.

public static implicit operator Rect((NFloat, NFloat, NFloat, NFloat) tuple)

Parameters

tuple (NFloat topLeft, NFloat topRight, NFloat bottomRight, NFloat bottomLeft)

Returns

Rect

operator !=(Rect, Rect)

Returns true if any of the rectangle fields are different.

public static bool operator !=(Rect lhs, Rect rhs)

Parameters

lhs Rect
rhs Rect

Returns

bool

operator -(Rect, Frame)

Returns a rectangle inset inward by a Frame.

public static Rect operator -(Rect rect, Frame frame)

Parameters

rect Rect
frame Frame

Returns

Rect