Table of Contents

Struct PixelRect

Namespace
Avalonia
Assembly
Avalonia.Base.dll

Represents a rectangle in device pixels.

public readonly struct PixelRect : IEquatable<PixelRect>
Implements
Inherited Members

Constructors

PixelRect(PixelPoint, PixelPoint)

Initializes a new instance of the PixelRect structure.

public PixelRect(PixelPoint topLeft, PixelPoint bottomRight)

Parameters

topLeft PixelPoint

The top left position of the rectangle.

bottomRight PixelPoint

The bottom right position of the rectangle.

PixelRect(PixelPoint, PixelSize)

Initializes a new instance of the PixelRect structure.

public PixelRect(PixelPoint position, PixelSize size)

Parameters

position PixelPoint

The position of the rectangle.

size PixelSize

The size of the rectangle.

PixelRect(PixelSize)

Initializes a new instance of the PixelRect structure.

public PixelRect(PixelSize size)

Parameters

size PixelSize

The size of the rectangle.

PixelRect(int, int, int, int)

Initializes a new instance of the PixelRect structure.

public PixelRect(int x, int y, int width, int height)

Parameters

x int

The X position.

y int

The Y position.

width int

The width.

height int

The height.

Properties

Bottom

Gets the bottom position of the rectangle.

public int Bottom { get; }

Property Value

int

BottomLeft

Gets the bottom left point of the rectangle.

public PixelPoint BottomLeft { get; }

Property Value

PixelPoint

BottomRight

Gets the bottom right point of the rectangle.

public PixelPoint BottomRight { get; }

Property Value

PixelPoint

Center

Gets the center point of the rectangle.

public PixelPoint Center { get; }

Property Value

PixelPoint

Height

Gets the height.

public int Height { get; }

Property Value

int

Position

Gets the position of the rectangle.

public PixelPoint Position { get; }

Property Value

PixelPoint

Right

Gets the right position of the rectangle.

public int Right { get; }

Property Value

int

Size

Gets the size of the rectangle.

public PixelSize Size { get; }

Property Value

PixelSize

TopLeft

Gets the top left point of the rectangle.

public PixelPoint TopLeft { get; }

Property Value

PixelPoint

TopRight

Gets the top right point of the rectangle.

public PixelPoint TopRight { get; }

Property Value

PixelPoint

Width

Gets the width.

public int Width { get; }

Property Value

int

X

Gets the X position.

public int X { get; }

Property Value

int

Y

Gets the Y position.

public int Y { get; }

Property Value

int

Methods

CenterRect(PixelRect)

Centers another rectangle in this rectangle.

public PixelRect CenterRect(PixelRect rect)

Parameters

rect PixelRect

The rectangle to center.

Returns

PixelRect

The centered rectangle.

Contains(PixelPoint)

Determines whether a point in the bounds of the rectangle.

public bool Contains(PixelPoint p)

Parameters

p PixelPoint

The point.

Returns

bool

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

Contains(PixelRect)

Determines whether the rectangle fully contains another rectangle.

public bool Contains(PixelRect r)

Parameters

r PixelRect

The rectangle.

Returns

bool

true if the rectangle is fully contained; otherwise false.

ContainsExclusive(PixelPoint)

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

public bool ContainsExclusive(PixelPoint p)

Parameters

p PixelPoint

The point.

Returns

bool

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

Equals(PixelRect)

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

public bool Equals(PixelRect other)

Parameters

other PixelRect

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.

FromRect(Rect, Vector)

Converts a Rect to device pixels using the specified scaling factor.

public static PixelRect FromRect(Rect rect, Vector scale)

Parameters

rect Rect

The rect.

scale Vector

The scaling factor.

Returns

PixelRect

The device-independent point.

FromRect(Rect, double)

Converts a Rect to device pixels using the specified scaling factor.

public static PixelRect FromRect(Rect rect, double scale)

Parameters

rect Rect

The rect.

scale double

The scaling factor.

Returns

PixelRect

The device-independent rect.

FromRectWithDpi(Rect, Vector)

Converts a Rect to device pixels using the specified dots per inch (DPI).

public static PixelRect FromRectWithDpi(Rect rect, Vector dpi)

Parameters

rect Rect

The rect.

dpi Vector

The dots per inch of the device.

Returns

PixelRect

The device-independent point.

FromRectWithDpi(Rect, double)

Converts a Rect to device pixels using the specified dots per inch (DPI).

public static PixelRect FromRectWithDpi(Rect rect, double dpi)

Parameters

rect Rect

The rect.

dpi double

The dots per inch of the device.

Returns

PixelRect

The device-independent point.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

The hash code.

Intersect(PixelRect)

Gets the intersection of two rectangles.

public PixelRect Intersect(PixelRect rect)

Parameters

rect PixelRect

The other rectangle.

Returns

PixelRect

The intersection.

Intersects(PixelRect)

Determines whether a rectangle intersects with this rectangle.

public bool Intersects(PixelRect rect)

Parameters

rect PixelRect

The other rectangle.

Returns

bool

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

Parse(string)

Parses a PixelRect string.

public static PixelRect Parse(string s)

Parameters

s string

The string.

Returns

PixelRect

The parsed PixelRect.

ToRect(Vector)

Converts the PixelRect to a device-independent Rect using the specified scaling factor.

public Rect ToRect(Vector scale)

Parameters

scale Vector

The scaling factor.

Returns

Rect

The device-independent rect.

ToRect(double)

Converts the PixelRect to a device-independent Rect using the specified scaling factor.

public Rect ToRect(double scale)

Parameters

scale double

The scaling factor.

Returns

Rect

The device-independent rect.

ToRectWithDpi(Vector)

Converts the PixelRect to a device-independent Rect using the specified dots per inch (DPI).

public Rect ToRectWithDpi(Vector dpi)

Parameters

dpi Vector

The dots per inch of the device.

Returns

Rect

The device-independent rect.

ToRectWithDpi(double)

Converts the PixelRect to a device-independent Rect using the specified dots per inch (DPI).

public Rect ToRectWithDpi(double dpi)

Parameters

dpi double

The dots per inch of the device.

Returns

Rect

The device-independent rect.

ToString()

Returns the string representation of the rectangle.

public override string ToString()

Returns

string

The string representation of the rectangle.

Translate(PixelVector)

Translates the rectangle by an offset.

public PixelRect Translate(PixelVector offset)

Parameters

offset PixelVector

The offset.

Returns

PixelRect

The translated rectangle.

Union(PixelRect)

Gets the union of two rectangles.

public PixelRect Union(PixelRect rect)

Parameters

rect PixelRect

The other rectangle.

Returns

PixelRect

The union.

WithHeight(int)

Returns a new PixelRect with the specified height.

public PixelRect WithHeight(int height)

Parameters

height int

The height.

Returns

PixelRect

The new PixelRect.

WithWidth(int)

Returns a new PixelRect with the specified width.

public PixelRect WithWidth(int width)

Parameters

width int

The width.

Returns

PixelRect

The new PixelRect.

WithX(int)

Returns a new PixelRect with the specified X position.

public PixelRect WithX(int x)

Parameters

x int

The x position.

Returns

PixelRect

The new PixelRect.

WithY(int)

Returns a new PixelRect with the specified Y position.

public PixelRect WithY(int y)

Parameters

y int

The y position.

Returns

PixelRect

The new PixelRect.

Operators

operator ==(PixelRect, PixelRect)

Checks for equality between two PixelRects.

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

Parameters

left PixelRect

The first rect.

right PixelRect

The second rect.

Returns

bool

True if the rects are equal; otherwise false.

operator !=(PixelRect, PixelRect)

Checks for inequality between two PixelRects.

public static bool operator !=(PixelRect left, PixelRect right)

Parameters

left PixelRect

The first rect.

right PixelRect

The second rect.

Returns

bool

True if the rects are unequal; otherwise false.