Struct Rect
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
Rect(Point, Size)
Creates a new Rect from a top-left point and a size.
public Rect(Point topLeft, Size size)
Parameters
Rect(Vector, Size)
Creates a new Rect from a top-left vector and a size.
public Rect(Vector topLeft, Size size)
Parameters
Fields
Height
The height of the rectangle.
public NFloat Height
Field Value
Width
The width of the rectangle.
public NFloat Width
Field Value
X
The X-coordinate of the rectangle’s top-left corner.
public NFloat X
Field Value
Y
The Y-coordinate of the rectangle’s top-left corner.
public NFloat Y
Field Value
Properties
Bottom
Returns the Y-coordinate of the bottom edge.
public NFloat Bottom { get; }
Property Value
BottomLeft
Returns the bottom-left point of the rectangle.
public Point BottomLeft { get; }
Property Value
BottomRight
Returns the bottom-right point of the rectangle.
public Point BottomRight { get; }
Property Value
Center
Returns the center point of the rectangle.
public Point Center { get; }
Property Value
Left
Returns the X-coordinate of the left edge.
public NFloat Left { get; }
Property Value
Right
Returns the X-coordinate of the right edge.
public NFloat Right { get; }
Property Value
Size
Gets or sets the size of the rectangle.
public Size Size { get; set; }
Property Value
Top
Returns the Y-coordinate of the top edge.
public NFloat Top { get; }
Property Value
TopCenter
Returns the top-center point of the rectangle.
public Point TopCenter { get; }
Property Value
TopLeft
Returns the top-left point of the rectangle.
public Point TopLeft { get; }
Property Value
TopRight
Returns the top-right point of the rectangle.
public Point TopRight { get; }
Property Value
Methods
Contains(Point)
Returns true if the specified point
lies within this rectangle.
public bool Contains(Point point)
Parameters
point
Point
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
obj
objectThe 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
Expand(NFloat)
Returns a rectangle expanded uniformly in all directions.
public Rect Expand(NFloat expand)
Parameters
expand
NFloat
Returns
Expand(NFloat, NFloat)
Returns a rectangle expanded horizontally and vertically by the specified amounts.
public Rect Expand(NFloat h, NFloat v)
Parameters
Returns
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
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
Returns
operator ==(Rect, Rect)
Returns true if two rectangles are equal in position and size.
public static bool operator ==(Rect lhs, Rect rhs)
Parameters
Returns
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
operator !=(Rect, Rect)
Returns true if any of the rectangle fields are different.
public static bool operator !=(Rect lhs, Rect rhs)
Parameters
Returns
operator -(Rect, Frame)
Returns a rectangle inset inward by a Frame.
public static Rect operator -(Rect rect, Frame frame)