Rectangle Struct
Namespace: Stride.Core.MathematicsAssembly: Stride.Core.Mathematics.dll
A rectangle structure defining X,Y,Width,Height.
[DataContract("Rectangle")]
[DataStyle(DataStyle.Compact)]
public struct Rectangle : IEquatable<Rectangle>
| Name | Description | |
|---|---|---|
| Constructors | ||
| Rectangle(Int32, Int32, Int32, Int32) | Initializes a new instance of the Rectangle struct. |
|
| Fields | ||
| Empty | An empty rectangle. |
|
| Height | Gets or sets the height. |
|
| Width | Gets or sets the width. |
|
| X | Gets or sets the X position. |
|
| Y | Gets or sets the Y position. |
|
| Properties | ||
| Bottom | Gets or sets the bottom. |
|
| BottomLeft | Gets the position of the bottom-left corner of the rectangle. |
|
| BottomRight | Gets the position of the bottom-right corner of the rectangle. |
|
| Center | Gets the Point that specifies the center of the rectangle. |
|
| IsEmpty | Gets a value that indicates whether the rectangle is empty. |
|
| Left | Gets or sets the left. |
|
| Location | Gets or sets the location. |
|
| Right | Gets or sets the right. |
|
| Size | Gets or sets the size of the rectangle. |
|
| Top | Gets or sets the top. |
|
| TopLeft | Gets the position of the top-left corner of the rectangle. |
|
| TopRight | Gets the position of the top-right corner of the rectangle. |
|
| Methods | ||
| Contains(Int2) | ||
| Contains(Point) | Determines whether this rectangle contains a specified Point. |
|
| Contains(ref Point, out Boolean) | Determines whether this rectangle contains a specified Point. |
|
| Contains(Rectangle) | Determines whether this rectangle entirely contains a specified rectangle. |
|
| Contains(ref Rectangle, out Boolean) | Determines whether this rectangle entirely contains a specified rectangle. |
|
| Contains(Vector2) | ||
| Contains(Int32, Int32) | Determines whether this rectangle contains a specified point represented by its x- and y-coordinates. |
|
| Contains(Single, Single) | Checks, if specified point is inside Rectangle. |
|
| Equals(Rectangle) | Determines whether the specified Rectangle is equal to this instance. |
|
| Equals(Object) | Determines whether the specified System.Object is equal to this instance. |
|
| GetHashCode() | Returns a hash code for this instance. |
|
| Inflate(Int32, Int32) | Pushes the edges of the rectangle out by the horizontal and vertical values specified. |
|
| Intersect(Rectangle, Rectangle) | Creates a rectangle defining the area where one rectangle overlaps with another rectangle. |
|
| Intersect(ref Rectangle, ref Rectangle, out Rectangle) | Creates a rectangle defining the area where one rectangle overlaps with another rectangle. |
|
| Intersects(Rectangle) | Determines whether a specified rectangle intersects with this rectangle. |
|
| Intersects(ref Rectangle, out Boolean) | Determines whether a specified rectangle intersects with this rectangle. |
|
| Offset(Point) | Changes the position of the rectangle. |
|
| Offset(Int32, Int32) | Changes the position of the rectangle. |
|
| ToString() | ||
| Union(Rectangle, Int2) | Creates a new rectangle that incorporate the provided point to the given rectangle. |
|
| Union(Rectangle, Rectangle) | Creates a new rectangle that exactly contains two other rectangles. |
|
| Union(ref Rectangle, ref Rectangle, out Rectangle) | Creates a new rectangle that exactly contains two other rectangles. |
|
| Operators | ||
| Equality(Rectangle, Rectangle) | Implements the operator ==. |
|
| Implicit(Rectangle to RectangleF) | Performs an implicit conversion to the RectangleF structure. |
|
| Inequality(Rectangle, Rectangle) | Implements the operator !=. |
|
Constructors
Rectangle(Int32, Int32, Int32, Int32)
Initializes a new instance of the Rectangle struct.
public Rectangle(int x, int y, int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | The left. |
| System.Int32 | y | The top. |
| System.Int32 | width | The width. |
| System.Int32 | height | The height. |
Fields
Empty
An empty rectangle.
public static readonly Rectangle Empty
Field Value
| Type | Description |
|---|---|
| Rectangle |
Height
Gets or sets the height.
[DataMember(3)]
public int Height
Field Value
| Type | Description |
|---|---|
| System.Int32 | The height. |
Width
Gets or sets the width.
[DataMember(2)]
public int Width
Field Value
| Type | Description |
|---|---|
| System.Int32 | The width. |
X
Gets or sets the X position.
[DataMember(0)]
public int X
Field Value
| Type | Description |
|---|---|
| System.Int32 | The X position. |
Y
Gets or sets the Y position.
[DataMember(1)]
public int Y
Field Value
| Type | Description |
|---|---|
| System.Int32 | The Y position. |
Properties
Bottom
Gets or sets the bottom.
public readonly int Bottom { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The bottom. |
BottomLeft
Gets the position of the bottom-left corner of the rectangle.
public readonly Point BottomLeft { get; }
Property Value
| Type | Description |
|---|---|
| Point | The bottom-left corner of the rectangle. |
BottomRight
Gets the position of the bottom-right corner of the rectangle.
public readonly Point BottomRight { get; }
Property Value
| Type | Description |
|---|---|
| Point | The bottom-right corner of the rectangle. |
Center
Gets the Point that specifies the center of the rectangle.
public readonly Point Center { get; }
Property Value
| Type | Description |
|---|---|
| Point | The center. |
IsEmpty
Gets a value that indicates whether the rectangle is empty.
public readonly bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
Left
Gets or sets the left.
public int Left { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The left. |
Location
Gets or sets the location.
public Point Location { get; set; }
Property Value
| Type | Description |
|---|---|
| Point | The location. |
Right
Gets or sets the right.
public readonly int Right { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The right. |
Size
Gets or sets the size of the rectangle.
public Size2 Size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size2 | The size of the rectangle. |
Top
Gets or sets the top.
public int Top { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The top. |
TopLeft
Gets the position of the top-left corner of the rectangle.
public readonly Point TopLeft { get; }
Property Value
| Type | Description |
|---|---|
| Point | The top-left corner of the rectangle. |
TopRight
Gets the position of the top-right corner of the rectangle.
public readonly Point TopRight { get; }
Property Value
| Type | Description |
|---|---|
| Point | The top-right corner of the rectangle. |
Methods
Contains(Int2)
public bool Contains(Int2 int2)
Parameters
| Type | Name | Description |
|---|---|---|
| Int2 | int2 | Coordinate Int2. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Contains(Point)
Determines whether this rectangle contains a specified Point.
public bool Contains(Point value)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | value | The Point to evaluate. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Contains(ref Point, out Boolean)
Determines whether this rectangle contains a specified Point.
public void Contains(ref Point value, out bool result)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | value | The Point to evaluate. |
| System.Boolean | result | [OutAttribute] true if the specified Point is contained within this rectangle; false otherwise. |
Contains(Rectangle)
Determines whether this rectangle entirely contains a specified rectangle.
public bool Contains(Rectangle value)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value | The rectangle to evaluate. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Contains(ref Rectangle, out Boolean)
Determines whether this rectangle entirely contains a specified rectangle.
public void Contains(ref Rectangle value, out bool result)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value | The rectangle to evaluate. |
| System.Boolean | result | [OutAttribute] On exit, is true if this rectangle entirely contains the specified rectangle, or false if not. |
Contains(Vector2)
public bool Contains(Vector2 vector2D)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | vector2D | Coordinate Vector2. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Contains(Int32, Int32)
Determines whether this rectangle contains a specified point represented by its x- and y-coordinates.
public bool Contains(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | The x-coordinate of the specified point. |
| System.Int32 | y | The y-coordinate of the specified point. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Contains(Single, Single)
Checks, if specified point is inside Rectangle.
public bool Contains(float x, float y)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | x | X point coordinate. |
| System.Single | y | Y point coordinate. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Equals(Rectangle)
Determines whether the specified Rectangle is equal to this instance.
public bool Equals(Rectangle other)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | other | The Rectangle to compare with this instance. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Equals(Object)
Determines whether the specified System.Object is equal to this instance.
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj | The System.Object to compare with this instance. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
Overrides
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
Overrides
Inflate(Int32, Int32)
Pushes the edges of the rectangle out by the horizontal and vertical values specified.
public void Inflate(int horizontalAmount, int verticalAmount)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | horizontalAmount | Value to push the sides out by. |
| System.Int32 | verticalAmount | Value to push the top and bottom out by. |
Intersect(Rectangle, Rectangle)
Creates a rectangle defining the area where one rectangle overlaps with another rectangle.
public static Rectangle Intersect(Rectangle value1, Rectangle value2)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value1 | The first rectangle to compare. |
| Rectangle | value2 | The second rectangle to compare. |
Returns
| Type | Description |
|---|---|
| Rectangle | The intersection rectangle. |
Intersect(ref Rectangle, ref Rectangle, out Rectangle)
Creates a rectangle defining the area where one rectangle overlaps with another rectangle.
public static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value1 | The first rectangle to compare. |
| Rectangle | value2 | The second rectangle to compare. |
| Rectangle | result | [OutAttribute] The area where the two first parameters overlap. |
Intersects(Rectangle)
Determines whether a specified rectangle intersects with this rectangle.
public bool Intersects(Rectangle value)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value | The rectangle to evaluate. |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Intersects(ref Rectangle, out Boolean)
Determines whether a specified rectangle intersects with this rectangle.
public void Intersects(ref Rectangle value, out bool result)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value | The rectangle to evaluate |
| System.Boolean | result | [OutAttribute] true if the specified rectangle intersects with this one; false otherwise. |
Offset(Point)
Changes the position of the rectangle.
public void Offset(Point amount)
Parameters
| Type | Name | Description |
|---|---|---|
| Point | amount | The values to adjust the position of the rectangle by. |
Offset(Int32, Int32)
Changes the position of the rectangle.
public void Offset(int offsetX, int offsetY)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | offsetX | Change in the x-position. |
| System.Int32 | offsetY | Change in the y-position. |
ToString()
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String |
Overrides
Union(Rectangle, Int2)
Creates a new rectangle that incorporate the provided point to the given rectangle.
public static Rectangle Union(Rectangle rectangle, Int2 point)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | rectangle | The original rectangle. |
| Int2 | point | The point to incorporate. |
Returns
| Type | Description |
|---|---|
| Rectangle | The union rectangle. |
Union(Rectangle, Rectangle)
Creates a new rectangle that exactly contains two other rectangles.
public static Rectangle Union(Rectangle value1, Rectangle value2)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value1 | The first rectangle to contain. |
| Rectangle | value2 | The second rectangle to contain. |
Returns
| Type | Description |
|---|---|
| Rectangle | The union rectangle. |
Union(ref Rectangle, ref Rectangle, out Rectangle)
Creates a new rectangle that exactly contains two other rectangles.
public static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value1 | The first rectangle to contain. |
| Rectangle | value2 | The second rectangle to contain. |
| Rectangle | result | [OutAttribute] The rectangle that must be the union of the first two rectangles. |
Operators
Equality(Rectangle, Rectangle)
Implements the operator ==.
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | left | The left. |
| Rectangle | right | The right. |
Returns
| Type | Description |
|---|---|
| System.Boolean | The result of the operator. |
Implicit(Rectangle to RectangleF)
Performs an implicit conversion to the RectangleF structure.
public static implicit operator RectangleF(Rectangle value)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | value | The source Rectangle value. |
Returns
| Type | Description |
|---|---|
| RectangleF | The converted structure. |
Remarks
Performs direct converstion from int to float.
Inequality(Rectangle, Rectangle)
Implements the operator !=.
public static bool operator !=(Rectangle left, Rectangle right)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | left | The left. |
| Rectangle | right | The right. |
Returns
| Type | Description |
|---|---|
| System.Boolean | The result of the operator. |