Table of Contents

Struct Rectangle

Namespace
SixLabors.ImageSharp
Assembly
SixLabors.ImageSharp.dll

Stores a set of four integers that represent the location and size of a rectangle.

public struct Rectangle : IEquatable<Rectangle>
Implements
Inherited Members

Remarks

This struct is fully mutable. This is done (against the guidelines) for the sake of performance, as it avoids the need to create new values for modification operations.

Constructors

Rectangle(Point, Size)

Initializes a new instance of the Rectangle struct.

public Rectangle(Point point, Size size)

Parameters

point Point

The Point which specifies the rectangles point in a two-dimensional plane.

size Size

The Size which specifies the rectangles height and width.

Rectangle(int, int, int, int)

Initializes a new instance of the Rectangle struct.

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

Parameters

x int

The horizontal position of the rectangle.

y int

The vertical position of the rectangle.

width int

The width of the rectangle.

height int

The height of the rectangle.

Fields

Empty

Represents a Rectangle that has X, Y, Width, and Height values set to zero.

public static readonly Rectangle Empty

Field Value

Rectangle

Properties

Bottom

Gets the y-coordinate of the bottom edge of this Rectangle.

public int Bottom { get; }

Property Value

int

Height

Gets or sets the height of this Rectangle.

public int Height { readonly get; set; }

Property Value

int

Left

Gets the x-coordinate of the left edge of this Rectangle.

public int Left { get; }

Property Value

int

Right

Gets the x-coordinate of the right edge of this Rectangle.

public int Right { get; }

Property Value

int

Top

Gets the y-coordinate of the top edge of this Rectangle.

public int Top { get; }

Property Value

int

Width

Gets or sets the width of this Rectangle.

public int Width { readonly get; set; }

Property Value

int

X

Gets or sets the x-coordinate of this Rectangle.

public int X { readonly get; set; }

Property Value

int

Y

Gets or sets the y-coordinate of this Rectangle.

public int Y { readonly get; set; }

Property Value

int

Methods

Ceiling(RectangleF)

Converts a RectangleF to a Rectangle by performing a ceiling operation on all the coordinates.

public static Rectangle Ceiling(RectangleF rectangle)

Parameters

rectangle RectangleF

The rectangle.

Returns

Rectangle

The Rectangle.

Center(Rectangle)

Returns the center point of the given Rectangle.

public static Point Center(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle.

Returns

Point

The Point.

Contains(Point)

Determines if the specified point is contained within the rectangular region defined by this Rectangle .

public bool Contains(Point point)

Parameters

point Point

The point.

Returns

bool

The bool.

Contains(Rectangle)

Determines if the rectangular region represented by rectangle is entirely contained within the rectangular region represented by this Rectangle .

public bool Contains(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle.

Returns

bool

The bool.

Contains(int, int)

Determines if the specified point is contained within the rectangular region defined by this Rectangle.

public bool Contains(int x, int y)

Parameters

x int

The x-coordinate of the given point.

y int

The y-coordinate of the given point.

Returns

bool

The bool.

Deconstruct(out int, out int, out int, out int)

Deconstructs this rectangle into four integers.

public void Deconstruct(out int x, out int y, out int width, out int height)

Parameters

x int

The out value for X.

y int

The out value for Y.

width int

The out value for the width.

height int

The out value for the height.

Equals(Rectangle)

public bool Equals(Rectangle other)

Parameters

other Rectangle

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

FromLTRB(int, int, int, int)

Creates a new Rectangle with the specified location and size.

public static Rectangle FromLTRB(int left, int top, int right, int bottom)

Parameters

left int

The left coordinate of the rectangle.

top int

The top coordinate of the rectangle.

right int

The right coordinate of the rectangle.

bottom int

The bottom coordinate of the rectangle.

Returns

Rectangle

The Rectangle.

GetHashCode()

public override int GetHashCode()

Returns

int

Inflate(Rectangle, int, int)

Creates a Rectangle that is inflated by the specified amount.

public static Rectangle Inflate(Rectangle rectangle, int x, int y)

Parameters

rectangle Rectangle

The rectangle.

x int

The amount to inflate the width by.

y int

The amount to inflate the height by.

Returns

Rectangle

A new Rectangle.

Inflate(Size)

Inflates this Rectangle by the specified amount.

public void Inflate(Size size)

Parameters

size Size

The size.

Inflate(int, int)

Inflates this Rectangle by the specified amount.

public void Inflate(int width, int height)

Parameters

width int

The width.

height int

The height.

Intersect(Rectangle)

Creates a Rectangle that represents the intersection between this Rectangle and the rectangle.

public void Intersect(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle.

Intersect(Rectangle, Rectangle)

Creates a rectangle that represents the intersection between a and b. If there is no intersection, an empty rectangle is returned.

public static Rectangle Intersect(Rectangle a, Rectangle b)

Parameters

a Rectangle

The first rectangle.

b Rectangle

The second rectangle.

Returns

Rectangle

The Rectangle.

IntersectsWith(Rectangle)

Determines if the specified Rectangle intersects the rectangular region defined by this Rectangle.

public bool IntersectsWith(Rectangle rectangle)

Parameters

rectangle Rectangle

The other Rectangle.

Returns

bool

The bool.

Offset(Point)

Adjusts the location of this rectangle by the specified amount.

public void Offset(Point point)

Parameters

point Point

The point.

Offset(int, int)

Adjusts the location of this rectangle by the specified amount.

public void Offset(int dx, int dy)

Parameters

dx int

The amount to offset the x-coordinate.

dy int

The amount to offset the y-coordinate.

Round(RectangleF)

Converts a RectangleF to a Rectangle by performing a round operation on all the coordinates.

public static Rectangle Round(RectangleF rectangle)

Parameters

rectangle RectangleF

The rectangle.

Returns

Rectangle

The Rectangle.

ToString()

public override string ToString()

Returns

string

Transform(Rectangle, Matrix3x2)

Transforms a rectangle by the given matrix.

public static RectangleF Transform(Rectangle rectangle, Matrix3x2 matrix)

Parameters

rectangle Rectangle

The source rectangle.

matrix Matrix3x2

The transformation matrix.

Returns

RectangleF

A transformed rectangle.

Truncate(RectangleF)

Converts a RectangleF to a Rectangle by performing a truncate operation on all the coordinates.

public static Rectangle Truncate(RectangleF rectangle)

Parameters

rectangle RectangleF

The rectangle.

Returns

Rectangle

The Rectangle.

Union(Rectangle, Rectangle)

Creates a rectangle that represents the union between a and b.

public static Rectangle Union(Rectangle a, Rectangle b)

Parameters

a Rectangle

The first rectangle.

b Rectangle

The second rectangle.

Returns

Rectangle

The Rectangle.

Operators

operator ==(Rectangle, Rectangle)

Compares two Rectangle objects for equality.

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

Parameters

left Rectangle

The Rectangle on the left side of the operand.

right Rectangle

The Rectangle on the right side of the operand.

Returns

bool

True if the current left is equal to the right parameter; otherwise, false.

implicit operator RectangleF(Rectangle)

Creates a RectangleF with the coordinates of the specified Rectangle.

public static implicit operator RectangleF(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle.

Returns

RectangleF

implicit operator Vector4(Rectangle)

Creates a Vector4 with the coordinates of the specified Rectangle.

public static implicit operator Vector4(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle.

Returns

Vector4

operator !=(Rectangle, Rectangle)

Compares two Rectangle objects for inequality.

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

Parameters

left Rectangle

The Rectangle on the left side of the operand.

right Rectangle

The Rectangle on the right side of the operand.

Returns

bool

True if the current left is unequal to the right parameter; otherwise, false.