Struct Rect
- Namespace
- Avalonia
- Assembly
- Avalonia.Base.dll
Defines a rectangle.
public readonly struct Rect : IEquatable<Rect>
- Implements
- Inherited Members
- Extension Methods
Constructors
Rect(Point, Point)
Initializes a new instance of the Rect structure.
public Rect(Point topLeft, Point bottomRight)
Parameters
topLeft
PointThe top left position of the rectangle.
bottomRight
PointThe bottom right position of the rectangle.
Rect(Point, Size)
Initializes a new instance of the Rect structure.
public Rect(Point position, Size size)
Parameters
Rect(Size)
Initializes a new instance of the Rect structure.
public Rect(Size size)
Parameters
size
SizeThe size of the rectangle.
Rect(double, double, double, double)
Initializes a new instance of the Rect structure.
public Rect(double x, double y, double width, double height)
Parameters
Properties
Bottom
Gets the bottom position of the rectangle.
public double Bottom { get; }
Property Value
BottomLeft
Gets the bottom left point of the rectangle.
public Point BottomLeft { get; }
Property Value
BottomRight
Gets the bottom right point of the rectangle.
public Point BottomRight { get; }
Property Value
Center
Gets the center point of the rectangle.
public Point Center { get; }
Property Value
Height
Gets the height.
public double Height { get; }
Property Value
Left
Gets the left position.
public double Left { get; }
Property Value
Position
Gets the position of the rectangle.
public Point Position { get; }
Property Value
Right
Gets the right position of the rectangle.
public double Right { get; }
Property Value
Size
Gets the size of the rectangle.
public Size Size { get; }
Property Value
Top
Gets the top position.
public double Top { get; }
Property Value
TopLeft
Gets the top left point of the rectangle.
public Point TopLeft { get; }
Property Value
TopRight
Gets the top right point of the rectangle.
public Point TopRight { get; }
Property Value
Width
Gets the width.
public double Width { get; }
Property Value
X
Gets the X position.
public double X { get; }
Property Value
Y
Gets the Y position.
public double Y { get; }
Property Value
Methods
CenterRect(Rect)
Centers another rectangle in this rectangle.
public Rect CenterRect(Rect rect)
Parameters
rect
RectThe rectangle to center.
Returns
- Rect
The centered rectangle.
Contains(Point)
Determines whether a point is in the bounds of the rectangle.
public bool Contains(Point p)
Parameters
p
PointThe point.
Returns
- bool
true if the point is in the bounds of the rectangle; otherwise false.
Contains(Rect)
Determines whether the rectangle fully contains another rectangle.
public bool Contains(Rect r)
Parameters
r
RectThe rectangle.
Returns
- bool
true if the rectangle is fully contained; otherwise false.
ContainsExclusive(Point)
Determines whether a point is in the bounds of the rectangle, exclusive of the rectangle's bottom/right edge.
public bool ContainsExclusive(Point p)
Parameters
p
PointThe point.
Returns
- bool
true if the point is in the bounds of the rectangle; otherwise false.
Deflate(Thickness)
Deflates the rectangle by a Thickness.
public Rect Deflate(Thickness thickness)
Parameters
thickness
ThicknessThe thickness to be subtracted for each side of the rectangle.
Returns
- Rect
The deflated rectangle.
Deflate(double)
Deflates the rectangle.
public Rect Deflate(double thickness)
Parameters
thickness
doubleThe thickness to be subtracted for each side of the rectangle.
Returns
- Rect
The deflated rectangle.
Equals(Rect)
Returns a boolean indicating whether the rect is equal to the other given rect.
public bool Equals(Rect other)
Parameters
other
RectThe other rect to test equality against.
Returns
- bool
True if this rect is equal to other; False otherwise.
Equals(object?)
Returns a boolean indicating whether the given object is equal to this rectangle.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare against.
Returns
- bool
True if the object is equal to this rectangle; false otherwise.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
The hash code.
Inflate(Thickness)
Inflates the rectangle.
public Rect Inflate(Thickness thickness)
Parameters
thickness
ThicknessThe thickness to be subtracted for each side of the rectangle.
Returns
- Rect
The inflated rectangle.
Inflate(double)
Inflates the rectangle.
public Rect Inflate(double thickness)
Parameters
thickness
doubleThe thickness to be subtracted for each side of the rectangle.
Returns
- Rect
The inflated rectangle.
Intersect(Rect)
Gets the intersection of two rectangles.
public Rect Intersect(Rect rect)
Parameters
rect
RectThe other rectangle.
Returns
- Rect
The intersection.
Intersects(Rect)
Determines whether a rectangle intersects with this rectangle.
public bool Intersects(Rect rect)
Parameters
rect
RectThe other rectangle.
Returns
- bool
True if the specified rectangle intersects with this one; otherwise false.
Normalize()
Normalizes the rectangle so both the Width and Height are positive, without changing the location of the rectangle
public Rect Normalize()
Returns
- Rect
Normalized Rect
Remarks
Empty rect will be return when Rect contains invalid values. Like NaN.
Parse(string)
Parses a Rect string.
public static Rect Parse(string s)
Parameters
s
stringThe string.
Returns
ToString()
Returns the string representation of the rectangle.
public override string ToString()
Returns
- string
The string representation of the rectangle.
TransformToAABB(Matrix)
Returns the axis-aligned bounding box of a transformed rectangle.
public Rect TransformToAABB(Matrix matrix)
Parameters
matrix
MatrixThe transform.
Returns
- Rect
The bounding box
Translate(Vector)
Translates the rectangle by an offset.
public Rect Translate(Vector offset)
Parameters
offset
VectorThe offset.
Returns
- Rect
The translated rectangle.
Union(Rect)
Gets the union of two rectangles.
public Rect Union(Rect rect)
Parameters
rect
RectThe other rectangle.
Returns
- Rect
The union.
WithHeight(double)
Returns a new Rect with the specified height.
public Rect WithHeight(double height)
Parameters
height
doubleThe height.
Returns
WithWidth(double)
Returns a new Rect with the specified width.
public Rect WithWidth(double width)
Parameters
width
doubleThe width.
Returns
WithX(double)
Returns a new Rect with the specified X position.
public Rect WithX(double x)
Parameters
x
doubleThe x position.
Returns
WithY(double)
Returns a new Rect with the specified Y position.
public Rect WithY(double y)
Parameters
y
doubleThe y position.
Returns
Operators
operator /(Rect, Vector)
Divides a rectangle by a vector.
public static Rect operator /(Rect rect, Vector scale)
Parameters
Returns
- Rect
The scaled rectangle.
operator ==(Rect, Rect)
Checks for equality between two Rects.
public static bool operator ==(Rect left, Rect right)
Parameters
Returns
- bool
True if the rects are equal; otherwise false.
operator !=(Rect, Rect)
Checks for inequality between two Rects.
public static bool operator !=(Rect left, Rect right)
Parameters
Returns
- bool
True if the rects are unequal; otherwise false.
operator *(Rect, Vector)
Multiplies a rectangle by a scaling vector.
public static Rect operator *(Rect rect, Vector scale)
Parameters
Returns
- Rect
The scaled rectangle.
operator *(Rect, double)
Multiplies a rectangle by a scale.
public static Rect operator *(Rect rect, double scale)
Parameters
Returns
- Rect
The scaled rectangle.