RectangleD Struct
Represents an axis-aligned rectangle with sub-pixel precision (see PointD for the coordinate system).
public readonly struct RectangleD : IEquatable<RectangleD>- Implements
Constructors
| Name | Description |
|---|---|
| RectangleD(double, double, double, double) | Initializes a new instance of the RectangleD struct. |
RectangleD(double, double, double, double)
RectangleD.csInitializes a new instance of the RectangleD struct.
Parameters
xdouble- The left coordinate.
ydouble- The top coordinate.
widthdouble- The width. Must be zero or positive, and finite.
heightdouble- The height. Must be zero or positive, and finite.
Exceptions
ArgumentOutOfRangeExceptionwidthorheightis negative or not a finite number.
Properties
| Name | Description |
|---|---|
| Bottom | Gets the bottom coordinate (Y + Height). |
| Center | Gets the point in the middle of the rectangle. |
| Empty | Gets an empty rectangle located at the origin. |
| Height | Gets the height. |
| IsEmpty | Gets a value indicating whether the rectangle has no area. |
| Left | Gets the left coordinate. |
| Location | Gets the top-left corner. |
| Right | Gets the right coordinate (X + Width). |
| Top | Gets the top coordinate. |
| Width | Gets the width. |
| X | Gets the left coordinate. |
| Y | Gets the top coordinate. |
Bottom
RectangleD.csCenter
RectangleD.csEmpty
RectangleD.csHeight
RectangleD.csIsEmpty
RectangleD.csLeft
RectangleD.csLocation
RectangleD.csRight
RectangleD.csWidth
RectangleD.csMethods
| Name | Description |
|---|---|
| Contains(PointD) | Gets a value indicating whether a point is inside the rectangle. The left and top sides are inside, the right and bottom sides are not. |
| Contains(RectangleD) | Gets a value indicating whether another rectangle lies entirely within this one. |
| Equals(RectangleD) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object?) | Indicates whether this instance and a specified object are equal. |
| FromLTRB(double, double, double, double) | Creates a rectangle from its edges. |
| FromRectangle(Rectangle) | Converts a rectangle of pixels to the area those pixels cover. |
| GetHashCode() | Returns the hash code for this instance. |
| Inflate(double) | Moves each side of the rectangle away from its center by the same distance, or toward it when the distance is negative. |
| Inflate(double, double) | Moves each side of the rectangle away from its center, or toward it when the distance is negative. A side does not move past the center: a rectangle reduced by more than half its size has no width or no height. |
| Intersect(RectangleD, RectangleD) | Gets the part two rectangles have in common. |
| IntersectsWith(RectangleD) | Gets a value indicating whether two rectangles have some area in common. |
| Offset(double, double) | Moves the rectangle. |
| ToString() | Returns the rectangle formatted as {X},{Y} {Width}x{Height}. |
| Union(RectangleD, RectangleD) | Gets the smallest rectangle containing two rectangles. A rectangle without area counts for its position: the bounds of a horizontal line have no height and still extend the result. |
Contains overloads
Contains(PointD)
RectangleD.csContains(RectangleD)
RectangleD.csGets a value indicating whether another rectangle lies entirely within this one.
public bool Contains(RectangleD rectangle)Parameters
rectangleRectangleD- The other rectangle.
Returns
bool true if no part of rectangle is outside this rectangle.
Equals overloads
Equals(RectangleD)
RectangleD.csIndicates whether the current object is equal to another object of the same type.
public bool Equals(RectangleD other)Parameters
otherRectangleD- An object to compare with this object.
Returns
bool true if the current object is equal to the other parameter; otherwise, false.
Equals(object?)
RectangleD.csFromLTRB(double, double, double, double)
RectangleD.csCreates a rectangle from its edges.
public static RectangleD FromLTRB(double left, double top, double right, double bottom)Parameters
leftdouble- The left coordinate.
topdouble- The top coordinate.
rightdouble- The right coordinate. Must not be less than
left. bottomdouble- The bottom coordinate. Must not be less than
top.
Returns
RectangleD The rectangle.
Exceptions
ArgumentOutOfRangeException- The bounds are inverted, or the size is not a finite number.
FromRectangle(Rectangle)
RectangleD.csConverts a rectangle of pixels to the area those pixels cover.
public static RectangleD FromRectangle(Rectangle rectangle)GetHashCode()
RectangleD.csInflate overloads
Inflate(double)
RectangleD.csMoves each side of the rectangle away from its center by the same distance, or toward it when the distance is negative.
public RectangleD Inflate(double distance)Parameters
distancedouble- The distance every side moves.
Returns
RectangleD The resized rectangle, around the same center.
Exceptions
ArgumentOutOfRangeException- The size of the result is not a finite number.
Inflate(double, double)
RectangleD.csMoves each side of the rectangle away from its center, or toward it when the distance is negative. A side does not move past the center: a rectangle reduced by more than half its size has no width or no height.
public RectangleD Inflate(double dx, double dy)Parameters
dxdouble- The distance the left and the right sides move.
dydouble- The distance the top and the bottom sides move.
Returns
RectangleD The resized rectangle, around the same center.
Exceptions
ArgumentOutOfRangeException- The size of the result is not a finite number.
Intersect(RectangleD, RectangleD)
RectangleD.csGets the part two rectangles have in common.
public static RectangleD Intersect(RectangleD a, RectangleD b)Parameters
aRectangleD- The first rectangle.
bRectangleD- The second rectangle.
Returns
RectangleD The common part, or RectangleD.Empty when the rectangles have no area in common.
IntersectsWith(RectangleD)
RectangleD.csGets a value indicating whether two rectangles have some area in common.
public bool IntersectsWith(RectangleD rectangle)Parameters
rectangleRectangleD- The other rectangle.
Returns
bool true if the rectangles overlap; rectangles that only touch do not.
Offset(double, double)
RectangleD.csMoves the rectangle.
public RectangleD Offset(double dx, double dy)ToString()
RectangleD.csUnion(RectangleD, RectangleD)
RectangleD.csGets the smallest rectangle containing two rectangles. A rectangle without area counts for its position: the bounds of a horizontal line have no height and still extend the result.
public static RectangleD Union(RectangleD a, RectangleD b)Parameters
aRectangleD- The first rectangle.
bRectangleD- The second rectangle.
Returns
RectangleD The rectangle containing both.
Operators
| Name | Description |
|---|---|
| operator ==(RectangleD, RectangleD) | Compares two rectangles for equality. |
| implicit operator RectangleD(Rectangle) | Converts a rectangle of pixels to the area those pixels cover. The conversion is lossless. |
| operator !=(RectangleD, RectangleD) | Compares two rectangles for inequality. |
operator ==(RectangleD, RectangleD)
RectangleD.csCompares two rectangles for equality.
public static bool operator ==(RectangleD left, RectangleD right)Parameters
leftRectangleD- The first rectangle.
rightRectangleD- The second rectangle.
Returns
bool true if both rectangles are equal; otherwise false.
implicit operator RectangleD(Rectangle)
RectangleD.csConverts a rectangle of pixels to the area those pixels cover. The conversion is lossless.
public static implicit operator RectangleD(Rectangle rectangle)operator !=(RectangleD, RectangleD)
RectangleD.csCompares two rectangles for inequality.
public static bool operator !=(RectangleD left, RectangleD right)Parameters
leftRectangleD- The first rectangle.
rightRectangleD- The second rectangle.
Returns
bool true if the rectangles differ; otherwise false.