Table of Contents

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 Point

The top left position of the rectangle.

bottomRight Point

The bottom right position of the rectangle.

Rect(Point, Size)

Initializes a new instance of the Rect structure.

public Rect(Point position, Size size)

Parameters

position Point

The position of the rectangle.

size Size

The size of the rectangle.

Rect(Size)

Initializes a new instance of the Rect structure.

public Rect(Size size)

Parameters

size Size

The 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

x double

The X position.

y double

The Y position.

width double

The width.

height double

The height.

Properties

Bottom

Gets the bottom position of the rectangle.

public double Bottom { get; }

Property Value

double

BottomLeft

Gets the bottom left point of the rectangle.

public Point BottomLeft { get; }

Property Value

Point

BottomRight

Gets the bottom right point of the rectangle.

public Point BottomRight { get; }

Property Value

Point

Center

Gets the center point of the rectangle.

public Point Center { get; }

Property Value

Point

Height

Gets the height.

public double Height { get; }

Property Value

double

Left

Gets the left position.

public double Left { get; }

Property Value

double

Position

Gets the position of the rectangle.

public Point Position { get; }

Property Value

Point

Right

Gets the right position of the rectangle.

public double Right { get; }

Property Value

double

Size

Gets the size of the rectangle.

public Size Size { get; }

Property Value

Size

Top

Gets the top position.

public double Top { get; }

Property Value

double

TopLeft

Gets the top left point of the rectangle.

public Point TopLeft { get; }

Property Value

Point

TopRight

Gets the top right point of the rectangle.

public Point TopRight { get; }

Property Value

Point

Width

Gets the width.

public double Width { get; }

Property Value

double

X

Gets the X position.

public double X { get; }

Property Value

double

Y

Gets the Y position.

public double Y { get; }

Property Value

double

Methods

CenterRect(Rect)

Centers another rectangle in this rectangle.

public Rect CenterRect(Rect rect)

Parameters

rect Rect

The 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 Point

The 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 Rect

The 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 Point

The 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 Thickness

The 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 double

The 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 Rect

The 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 object

The 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 Thickness

The 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 double

The 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 Rect

The other rectangle.

Returns

Rect

The intersection.

Intersects(Rect)

Determines whether a rectangle intersects with this rectangle.

public bool Intersects(Rect rect)

Parameters

rect Rect

The 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 string

The string.

Returns

Rect

The parsed Rect.

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 Matrix

The transform.

Returns

Rect

The bounding box

Translate(Vector)

Translates the rectangle by an offset.

public Rect Translate(Vector offset)

Parameters

offset Vector

The offset.

Returns

Rect

The translated rectangle.

Union(Rect)

Gets the union of two rectangles.

public Rect Union(Rect rect)

Parameters

rect Rect

The other rectangle.

Returns

Rect

The union.

WithHeight(double)

Returns a new Rect with the specified height.

public Rect WithHeight(double height)

Parameters

height double

The height.

Returns

Rect

The new Rect.

WithWidth(double)

Returns a new Rect with the specified width.

public Rect WithWidth(double width)

Parameters

width double

The width.

Returns

Rect

The new Rect.

WithX(double)

Returns a new Rect with the specified X position.

public Rect WithX(double x)

Parameters

x double

The x position.

Returns

Rect

The new Rect.

WithY(double)

Returns a new Rect with the specified Y position.

public Rect WithY(double y)

Parameters

y double

The y position.

Returns

Rect

The new Rect.

Operators

operator /(Rect, Vector)

Divides a rectangle by a vector.

public static Rect operator /(Rect rect, Vector scale)

Parameters

rect Rect

The rectangle.

scale Vector

The vector scale.

Returns

Rect

The scaled rectangle.

operator ==(Rect, Rect)

Checks for equality between two Rects.

public static bool operator ==(Rect left, Rect right)

Parameters

left Rect

The first rect.

right Rect

The second rect.

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

left Rect

The first rect.

right Rect

The second rect.

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

rect Rect

The rectangle.

scale Vector

The vector scale.

Returns

Rect

The scaled rectangle.

operator *(Rect, double)

Multiplies a rectangle by a scale.

public static Rect operator *(Rect rect, double scale)

Parameters

rect Rect

The rectangle.

scale double

The scale.

Returns

Rect

The scaled rectangle.