Struct RectangleF
Stores a set of four floating-point numbers that represent the location and size of a rectangle.
Namespace: Evergine.Mathematics
Assembly: Evergine.Mathematics.dll
Syntax
public struct RectangleF
Constructors
RectangleF(float, float, float, float)
Initializes a new instance of the RectangleF struct with the specified location and size.
Declaration
public RectangleF(float x, float y, float width, float height)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | The x-coordinate of the upper-left corner of the rectangle. |
| float | y | The y-coordinate of the upper-left corner of the rectangle. |
| float | width | The width of the rectangle. |
| float | height | The height of the rectangle. |
Fields
Height
Gets or sets the height of this RectangleF structure. The default value is 0.
Declaration
public float Height
Field Value
| Type | Description |
|---|---|
| float |
Width
Gets or sets the width of this RectangleF structure. The default is 0.
Declaration
public float Width
Field Value
| Type | Description |
|---|---|
| float |
X
Gets or sets the x-coordinate of the upper-left corner of this RectangleF structure. The default is 0.
Declaration
public float X
Field Value
| Type | Description |
|---|---|
| float |
Y
Gets or sets the y-coordinate of the upper-left corner of this RectangleF structure. The default value is 0.
Declaration
public float Y
Field Value
| Type | Description |
|---|---|
| float |
Properties
Bottom
Gets the y-coordinate that is the sum of Y and Height of this RectangleF structure.
Declaration
public float Bottom { get; }
Property Value
| Type | Description |
|---|---|
| float |
Center
Gets the coordinates of the center of this RectangleF structure.
Declaration
public Vector2 Center { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 | A Vector2 that represents the center of this RectangleF structure. |
Empty
Gets an instance of the RectangleF class with its members uninitialized.
Declaration
public static RectangleF Empty { get; }
Property Value
| Type | Description |
|---|---|
| RectangleF |
Remarks
The members of the new RectangleF are left uninitialized.
IsEmpty
Gets a value indicating whether the Width or Height property of this RectangleF has a value of zero.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool | This property returns |
Left
Gets the x-coordinate of the left edge of this RectangleF structure.
Declaration
public float Left { get; }
Property Value
| Type | Description |
|---|---|
| float |
Location
Gets or sets the coordinates of the upper-left corner of this RectangleF structure.
Declaration
public Vector2 Location { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector2 | A Vector2 that represents the upper-left corner of this RectangleF structure. |
Right
Gets the x-coordinate that is the sum of X and Width of this RectangleF structure.
Declaration
public float Right { get; }
Property Value
| Type | Description |
|---|---|
| float |
Top
Gets the y-coordinate of the top edge of this RectangleF structure.
Declaration
public float Top { get; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
Contains(RectangleF)
Determines if the rectangular region represented by rect is entirely contained
within this RectangleF structure.
Declaration
public bool Contains(RectangleF rect)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | rect | The RectangleF to test. |
Returns
| Type | Description |
|---|---|
| bool | This method returns |
Contains(ref RectangleF, out bool)
Determines if the rectangular region represented by rect is entirely contained
within this RectangleF structure.
Declaration
public void Contains(ref RectangleF rect, out bool result)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | rect | The RectangleF to test. |
| bool | result | If set to |
Contains(Vector2)
Determines if the specified point is contained within this RectangleF structure.
Declaration
public bool Contains(Vector2 pt)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | pt | The Vector2 to test. |
Returns
| Type | Description |
|---|---|
| bool | This method returns |
Contains(ref Vector2, out bool)
Determines if the specified point is contained within this RectangleF structure.
Declaration
public void Contains(ref Vector2 pt, out bool result)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | pt | The Vector2 to test. |
| bool | result | If set to |
Contains(float, float)
Determines if the specified point is contained within this RectangleF structure.
Declaration
public bool Contains(float x, float y)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | The x-coordinate of the point to test. |
| float | y | The y-coordinate of the point to test. |
Returns
| Type | Description |
|---|---|
| bool | Returns |
Equals(RectangleF)
Tests whether other has the same location and size as this RectangleF.
Declaration
public bool Equals(RectangleF other)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | other | The RectangleF to test. |
Returns
| Type | Description |
|---|---|
| bool | This method returns |
Equals(ref RectangleF)
Tests whether other has the same location and size as this RectangleF.
Declaration
public bool Equals(ref RectangleF other)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | other | The RectangleF to test. |
Returns
| Type | Description |
|---|---|
| bool | Returns |
Equals(object)
Tests whether obj is a RectangleF with the same location and size as this RectangleF.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to test. |
Returns
| Type | Description |
|---|---|
| bool | This method returns |
Overrides
GetHashCode()
Gets the hash code for this RectangleF structure. For information about the use of hash codes, see GetHashCode().
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
Overrides
GetPoints()
Gets the corner points of this RectangleF structure.
Declaration
public Vector2[] GetPoints()
Returns
| Type | Description |
|---|---|
| Vector2[] | A Vector2[] that represent the corner points of this RectangleF structure. |
Inflate(float, float)
Enlarges this RectangleF structure by the specified amount.
Declaration
public void Inflate(float horizontalAmount, float verticalAmount)
Parameters
| Type | Name | Description |
|---|---|---|
| float | horizontalAmount | The amount to inflate this RectangleF structure horizontally. |
| float | verticalAmount | The amount to inflate this RectangleF structure vertically. |
Remarks
This method enlarges this rectangle, not a copy of it. The rectangle is enlarged in both directions along an axis. For example, if a 50 by 50 rectangle is inflated by 50 on the x-axis, the resultant rectangle will be 150 units long (the original 50, the 50 in the minus direction, and the 50 in the plus direction), maintaining the rectangle's geometric center. If either x or y is negative, the RectangleF is deflated in the corresponding direction.
Intersect(RectangleF, RectangleF)
Returns a RectangleF structure that represents the intersection of two rectangles. If there is no intersection, an empty RectangleF is returned.
Declaration
public static RectangleF Intersect(RectangleF a, RectangleF b)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | a | A rectangle to intersect. |
| RectangleF | b | A second rectangle to intersect. |
Returns
| Type | Description |
|---|---|
| RectangleF | A third RectangleF structure whose size represents the overlapping area of the two specified rectangles. |
Intersect(ref RectangleF, ref RectangleF, out RectangleF)
Calculates a RectangleF structure that represents the intersection of two rectangles. If there is no intersection, an empty RectangleF is returned.
Declaration
public static void Intersect(ref RectangleF a, ref RectangleF b, out RectangleF result)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | a | A rectangle to intersect. |
| RectangleF | b | A second rectangle to intersect. |
| RectangleF | result | A rectangle that represents the intersection of the two rectangles. |
Intersects(RectangleF)
Determines if this rectangle intersects with rect.
Declaration
public bool Intersects(RectangleF rect)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | rect | The rectangle to test. |
Returns
| Type | Description |
|---|---|
| bool | Returns |
Intersects(ref RectangleF, out bool)
Determines if this rectangle intersects with rect.
Declaration
public void Intersects(ref RectangleF rect, out bool result)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | rect | The rectangle to test. |
| bool | result | If set to |
Offset(Vector2)
Adjusts the location of this rectangle by the specified amount.
Declaration
public void Offset(Vector2 amount)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | amount | The amount to offset the location. |
Offset(float, float)
Adjusts the location of this rectangle by the specified amount.
Declaration
public void Offset(float offsetX, float offsetY)
Parameters
| Type | Name | Description |
|---|---|---|
| float | offsetX | The amount to offset the location horizontally. |
| float | offsetY | The amount to offset the location vertically. |
ToString()
Converts the Location and Size of this RectangleF to a human-readable string.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string that contains the position, width, and height of this RectangleF structure. For example, "{X:20, Y:20, Width:100, Height:50}". |
Overrides
ToVector4()
Declaration
public Vector4 ToVector4()
Returns
| Type | Description |
|---|---|
| Vector4 | A Vector4 that contains the X, Y, Width, and Height of this RectangleF. |
ToVector4(ref Vector4)
Declaration
public void ToVector4(ref Vector4 vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | vector | Vector4 reference to pass RectangleF values. |
Union(RectangleF, RectangleF)
Creates the smallest possible third rectangle that can contain both of the two rectangles that form a union.
Declaration
public static RectangleF Union(RectangleF a, RectangleF b)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | a | A rectangle to union. |
| RectangleF | b | A second rectangle to union. |
Returns
| Type | Description |
|---|---|
| RectangleF | A third RectangleF structure that contains both of the two rectangles that form the union. |
Union(ref RectangleF, ref RectangleF, out RectangleF)
Calculates the smallest possible third rectangle that can contain both rectangles that form a union.
Declaration
public static void Union(ref RectangleF a, ref RectangleF b, out RectangleF result)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | a | A rectangle to union. |
| RectangleF | b | A second rectangle to union. |
| RectangleF | result | The smallest possible third rectangle that can contain both rectangles that form a union. |
Operators
operator ==(RectangleF, RectangleF)
Tests whether two RectangleF structures have equal location and size.
Declaration
public static bool operator ==(RectangleF left, RectangleF right)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | left | The RectangleF structure that is to the left of the inequality operator. |
| RectangleF | right | The RectangleF structure that is to the right of the inequality operator. |
Returns
| Type | Description |
|---|---|
| bool | This operator returns |
implicit operator RectangleF(Rectangle)
Converts the specified Rectangle structure to a RectangleF structure.
Declaration
public static implicit operator RectangleF(Rectangle r)
Parameters
| Type | Name | Description |
|---|---|---|
| Rectangle | r | The rectangle. |
Returns
| Type | Description |
|---|---|
| RectangleF | The RectangleF structure converted from the specified Rectangle structure. |
operator !=(RectangleF, RectangleF)
Tests whether two RectangleF structures differ in location or size.
Declaration
public static bool operator !=(RectangleF left, RectangleF right)
Parameters
| Type | Name | Description |
|---|---|---|
| RectangleF | left | The RectangleF structure that is to the left of the inequality operator. |
| RectangleF | right | The RectangleF structure that is to the right of the inequality operator. |
Returns
| Type | Description |
|---|---|
| bool | This operator returns |