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
PointThe Point which specifies the rectangles point in a two-dimensional plane.
size
SizeThe 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
intThe horizontal position of the rectangle.
y
intThe vertical position of the rectangle.
width
intThe width of the rectangle.
height
intThe 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
Properties
Bottom
Gets the y-coordinate of the bottom edge of this Rectangle.
public int Bottom { get; }
Property Value
Height
Gets or sets the height of this Rectangle.
public int Height { readonly get; set; }
Property Value
Left
Gets the x-coordinate of the left edge of this Rectangle.
public int Left { get; }
Property Value
Right
Gets the x-coordinate of the right edge of this Rectangle.
public int Right { get; }
Property Value
Top
Gets the y-coordinate of the top edge of this Rectangle.
public int Top { get; }
Property Value
Width
Gets or sets the width of this Rectangle.
public int Width { readonly get; set; }
Property Value
X
Gets or sets the x-coordinate of this Rectangle.
public int X { readonly get; set; }
Property Value
Y
Gets or sets the y-coordinate of this Rectangle.
public int Y { readonly get; set; }
Property Value
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
RectangleFThe rectangle.
Returns
Center(Rectangle)
Returns the center point of the given Rectangle.
public static Point Center(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle.
Returns
Contains(Point)
Determines if the specified point is contained within the rectangular region defined by this Rectangle .
public bool Contains(Point point)
Parameters
point
PointThe point.
Returns
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
RectangleThe rectangle.
Returns
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
Returns
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
intThe out value for X.
y
intThe out value for Y.
width
intThe out value for the width.
height
intThe out value for the height.
Equals(Rectangle)
public bool Equals(Rectangle other)
Parameters
other
Rectangle
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
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
intThe left coordinate of the rectangle.
top
intThe top coordinate of the rectangle.
right
intThe right coordinate of the rectangle.
bottom
intThe bottom coordinate of the rectangle.
Returns
GetHashCode()
public override int GetHashCode()
Returns
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
RectangleThe rectangle.
x
intThe amount to inflate the width by.
y
intThe amount to inflate the height by.
Returns
Inflate(Size)
Inflates this Rectangle by the specified amount.
public void Inflate(Size size)
Parameters
size
SizeThe size.
Inflate(int, int)
Inflates this Rectangle by the specified amount.
public void Inflate(int width, int height)
Parameters
Intersect(Rectangle)
Creates a Rectangle that represents the intersection between this Rectangle and the rectangle
.
public void Intersect(Rectangle rectangle)
Parameters
rectangle
RectangleThe 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
Returns
IntersectsWith(Rectangle)
public bool IntersectsWith(Rectangle rectangle)
Parameters
rectangle
RectangleThe other Rectangle.
Returns
Offset(Point)
Adjusts the location of this rectangle by the specified amount.
public void Offset(Point point)
Parameters
point
PointThe point.
Offset(int, int)
Adjusts the location of this rectangle by the specified amount.
public void Offset(int dx, int dy)
Parameters
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
RectangleFThe rectangle.
Returns
ToString()
public override string ToString()
Returns
Transform(Rectangle, Matrix3x2)
Transforms a rectangle by the given matrix.
public static RectangleF Transform(Rectangle rectangle, Matrix3x2 matrix)
Parameters
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
RectangleFThe rectangle.
Returns
Union(Rectangle, Rectangle)
Creates a rectangle that represents the union between a
and b
.
public static Rectangle Union(Rectangle a, Rectangle b)
Parameters
Returns
Operators
operator ==(Rectangle, Rectangle)
Compares two Rectangle objects for equality.
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
left
RectangleThe Rectangle on the left side of the operand.
right
RectangleThe 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
RectangleThe rectangle.
Returns
implicit operator Vector4(Rectangle)
public static implicit operator Vector4(Rectangle rectangle)
Parameters
rectangle
RectangleThe rectangle.
Returns
operator !=(Rectangle, Rectangle)
Compares two Rectangle objects for inequality.
public static bool operator !=(Rectangle left, Rectangle right)
Parameters
left
RectangleThe Rectangle on the left side of the operand.
right
RectangleThe Rectangle on the right side of the operand.
Returns
- bool
True if the current left is unequal to the
right
parameter; otherwise, false.