Skip to main content

Rect Struct

Definition​

Namespace:Avalonia
Assembly:Avalonia.Base
Package:Avalonia
Source:Rect.cs

Defines a rectangle.

public struct Rect

Inheritance: ValueType -> Rect

Implements: IEquatable<Rect>

Constructors​

NameDescription
Rect (4 overloads)Initializes a new instance of the Avalonia.Rect structure.

Rect overloads​

Rect Constructor​

Initializes a new instance of the Avalonia.Rect structure.

public Rect(Avalonia.Point topLeft, Avalonia.Point bottomRight)
Parameters​

topLeft Avalonia.Point

The top left position of the rectangle.

bottomRight Avalonia.Point

The bottom right position of the rectangle.

Rect Constructor​

Initializes a new instance of the Avalonia.Rect structure.

public Rect(Avalonia.Point position, Avalonia.Size size)
Parameters​

position Avalonia.Point

The position of the rectangle.

size Avalonia.Size

The size of the rectangle.

Rect Constructor​

Initializes a new instance of the Avalonia.Rect structure.

public Rect(Avalonia.Size size)
Parameters​

size Avalonia.Size

The size of the rectangle.

Rect Constructor​

Initializes a new instance of the Avalonia.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.

Methods​

NameDescription
CenterRectCenters another rectangle in this rectangle.
Contains (2 overloads)Determines whether a point is in the bounds of the rectangle.
ContainsExclusiveDetermines whether a point is in the bounds of the rectangle, exclusive of the rectangle's bottom/right edge.
Deflate (2 overloads)Deflates the rectangle by a Avalonia.Thickness.
Equals (2 overloads)Returns a boolean indicating whether the rect is equal to the other given rect.
GetHashCodeReturns the hash code for this instance.
Inflate (2 overloads)Inflates the rectangle.
IntersectGets the intersection of two rectangles.
IntersectsDetermines whether a rectangle intersects with this rectangle.
NormalizeNormalizes the rectangle so both the Avalonia.Rect.Width and Avalonia.Rect.Height are positive, without changing the location of the rectangle
ParseParses a Avalonia.Rect string.
ToStringReturns the string representation of the rectangle.
TransformToAABBReturns the axis-aligned bounding box of a transformed rectangle.
TranslateTranslates the rectangle by an offset.
UnionGets the union of two rectangles.
WithHeightReturns a new Avalonia.Rect with the specified height.
WithWidthReturns a new Avalonia.Rect with the specified width.
WithXReturns a new Avalonia.Rect with the specified X position.
WithYReturns a new Avalonia.Rect with the specified Y position.

CenterRect Method​

Centers another rectangle in this rectangle.

public Avalonia.Rect CenterRect(Avalonia.Rect rect)

Parameters​

rect Avalonia.Rect

The rectangle to center.

Returns​

Avalonia.Rect

The centered rectangle.

Contains overloads​

Contains Method​

Determines whether a point is in the bounds of the rectangle.

public bool Contains(Avalonia.Point p)
Parameters​

p Avalonia.Point

The point.

Returns​

bool

true if the point is in the bounds of the rectangle; otherwise false.

Contains Method​

Determines whether the rectangle fully contains another rectangle.

public bool Contains(Avalonia.Rect r)
Parameters​

r Avalonia.Rect

The rectangle.

Returns​

bool

true if the rectangle is fully contained; otherwise false.

ContainsExclusive Method​

Determines whether a point is in the bounds of the rectangle, exclusive of the rectangle's bottom/right edge.

public bool ContainsExclusive(Avalonia.Point p)

Parameters​

p Avalonia.Point

The point.

Returns​

bool

true if the point is in the bounds of the rectangle; otherwise false.

Deflate overloads​

Deflate Method​

Deflates the rectangle by a Avalonia.Thickness.

public Avalonia.Rect Deflate(Avalonia.Thickness thickness)
Parameters​

thickness Avalonia.Thickness

The thickness to be subtracted for each side of the rectangle.

Returns​

Avalonia.Rect

The deflated rectangle.

Deflate Method​

Deflates the rectangle.

public Avalonia.Rect Deflate(double thickness)
Parameters​

thickness double

The thickness to be subtracted for each side of the rectangle.

Returns​

Avalonia.Rect

The deflated rectangle.

Equals overloads​

Equals Method​

Returns a boolean indicating whether the rect is equal to the other given rect.

public bool Equals(Avalonia.Rect other)
Parameters​

other Avalonia.Rect

The other rect to test equality against.

Returns​

bool

True if this rect is equal to other; False otherwise.

Equals Method​

Returns a boolean indicating whether the given object is equal to this rectangle.

public 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 Method​

Returns the hash code for this instance.

public int GetHashCode()

Returns​

int

The hash code.

Inflate overloads​

Inflate Method​

Inflates the rectangle.

public Avalonia.Rect Inflate(Avalonia.Thickness thickness)
Parameters​

thickness Avalonia.Thickness

The thickness to be subtracted for each side of the rectangle.

Returns​

Avalonia.Rect

The inflated rectangle.

Inflate Method​

Inflates the rectangle.

public Avalonia.Rect Inflate(double thickness)
Parameters​

thickness double

The thickness to be subtracted for each side of the rectangle.

Returns​

Avalonia.Rect

The inflated rectangle.

Intersect Method​

Gets the intersection of two rectangles.

public Avalonia.Rect Intersect(Avalonia.Rect rect)

Parameters​

rect Avalonia.Rect

The other rectangle.

Returns​

Avalonia.Rect

The intersection.

Intersects Method​

Determines whether a rectangle intersects with this rectangle.

public bool Intersects(Avalonia.Rect rect)

Parameters​

rect Avalonia.Rect

The other rectangle.

Returns​

bool

True if the specified rectangle intersects with this one; otherwise false.

Normalize Method​

Normalizes the rectangle so both the Avalonia.Rect.Width and Avalonia.Rect.Height are positive, without changing the location of the rectangle

public Avalonia.Rect Normalize()

Returns​

Avalonia.Rect

Normalized Rect

Remarks​

Empty rect will be return when Rect contains invalid values. Like NaN.

Parse Method​

Parses a Avalonia.Rect string.

public Avalonia.Rect Parse(string s)

Parameters​

s string

The string.

Returns​

Avalonia.Rect

The parsed Avalonia.Rect.

ToString Method​

Returns the string representation of the rectangle.

public string ToString()

Returns​

string

The string representation of the rectangle.

TransformToAABB Method​

Returns the axis-aligned bounding box of a transformed rectangle.

public Avalonia.Rect TransformToAABB(Avalonia.Matrix matrix)

Parameters​

matrix Avalonia.Matrix

The transform.

Returns​

Avalonia.Rect

The bounding box

Translate Method​

Translates the rectangle by an offset.

public Avalonia.Rect Translate(Avalonia.Vector offset)

Parameters​

offset Avalonia.Vector

The offset.

Returns​

Avalonia.Rect

The translated rectangle.

Union Method​

Gets the union of two rectangles.

public Avalonia.Rect Union(Avalonia.Rect rect)

Parameters​

rect Avalonia.Rect

The other rectangle.

Returns​

Avalonia.Rect

The union.

WithHeight Method​

Returns a new Avalonia.Rect with the specified height.

public Avalonia.Rect WithHeight(double height)

Parameters​

height double

The height.

Returns​

Avalonia.Rect

The new Avalonia.Rect.

WithWidth Method​

Returns a new Avalonia.Rect with the specified width.

public Avalonia.Rect WithWidth(double width)

Parameters​

width double

The width.

Returns​

Avalonia.Rect

The new Avalonia.Rect.

WithX Method​

Returns a new Avalonia.Rect with the specified X position.

public Avalonia.Rect WithX(double x)

Parameters​

x double

The x position.

Returns​

Avalonia.Rect

The new Avalonia.Rect.

WithY Method​

Returns a new Avalonia.Rect with the specified Y position.

public Avalonia.Rect WithY(double y)

Parameters​

y double

The y position.

Returns​

Avalonia.Rect

The new Avalonia.Rect.

Properties​

NameDescription
BottomGets the bottom position of the rectangle.
BottomLeftGets the bottom left point of the rectangle.
BottomRightGets the bottom right point of the rectangle.
CenterGets the center point of the rectangle.
HeightGets the height.
LeftGets the left position.
PositionGets the position of the rectangle.
RightGets the right position of the rectangle.
SizeGets the size of the rectangle.
TopGets the top position.
TopLeftGets the top left point of the rectangle.
TopRightGets the top right point of the rectangle.
WidthGets the width.
XGets the X position.
YGets the Y position.

Bottom Property​

Gets the bottom position of the rectangle.

public double Bottom { get; set; }

BottomLeft Property​

Gets the bottom left point of the rectangle.

public Avalonia.Point BottomLeft { get; set; }

BottomRight Property​

Gets the bottom right point of the rectangle.

public Avalonia.Point BottomRight { get; set; }

Center Property​

Gets the center point of the rectangle.

public Avalonia.Point Center { get; set; }

Height Property​

Gets the height.

public double Height { get; set; }

Left Property​

Gets the left position.

public double Left { get; set; }

Position Property​

Gets the position of the rectangle.

public Avalonia.Point Position { get; set; }

Right Property​

Gets the right position of the rectangle.

public double Right { get; set; }

Size Property​

Gets the size of the rectangle.

public Avalonia.Size Size { get; set; }

Top Property​

Gets the top position.

public double Top { get; set; }

TopLeft Property​

Gets the top left point of the rectangle.

public Avalonia.Point TopLeft { get; set; }

TopRight Property​

Gets the top right point of the rectangle.

public Avalonia.Point TopRight { get; set; }

Width Property​

Gets the width.

public double Width { get; set; }

X Property​

Gets the X position.

public double X { get; set; }

Y Property​

Gets the Y position.

public double Y { get; set; }