Struct Rectangle
- Namespace
- SimulationFramework
- Assembly
- SimulationFramework.dll
An axis-aligned floating-point rectangle consisting of a position and size.
public struct Rectangle : IEquatable<Rectangle>
- Implements
- Inherited Members
- Extension Methods
Constructors
Rectangle(Vector2, Vector2, Alignment)
Creates a new rectangle from the provided position and size.
public Rectangle(Vector2 position, Vector2 size, Alignment alignment = Alignment.TopLeft)
Parameters
position
Vector2The position of the rectangle.
size
Vector2The size of the rectangle.
alignment
AlignmentThe relative location of
position
on the rectangle.
Rectangle(float, float, float, float, Alignment)
Creates a new rectangle from the provided position and size.
public Rectangle(float x, float y, float width, float height, Alignment alignment = Alignment.TopLeft)
Parameters
x
floatThe x-coordinate of the position of the rectangle.
y
floatThe y-coordinate of the position of the rectangle.
width
floatThe width of the rectangle.
height
floatThe height of the rectangle.
alignment
AlignmentThe relative location of (
x
,y
) on the rectangle.
Fields
Height
The height of the rectangle.
public float Height
Field Value
Width
The width of the rectangle.
public float Width
Field Value
X
The x-coordinate of the top-left corner of the rectangle.
public float X
Field Value
Y
The y-coordinate of the top-left corner of the rectangle.
public float Y
Field Value
Properties
Center
The center of the rectangle.
public Vector2 Center { readonly get; set; }
Property Value
Position
The top-left corner of the rectangle.
public Vector2 Position { readonly get; set; }
Property Value
Size
The size of the rectangle.
public Vector2 Size { readonly get; set; }
Property Value
Methods
ContainsPoint(Vector2)
Determines if the rectangle contains the provided point.
public bool ContainsPoint(Vector2 point)
Parameters
point
Vector2The point to check the rectangle for.
Returns
Equals(Rectangle)
Indicates if this rectangle is equal to another.
public readonly bool Equals(Rectangle other)
Parameters
other
RectangleThe rectangle to compare against this one.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current instance.
Returns
- bool
true if
obj
and this instance are the same type and represent the same value; otherwise, false.
FromLTRB(float, float, float, float)
Creates a rectangle given the absolute position of each of its sides.
public static Rectangle FromLTRB(float left, float top, float right, float bottom)
Parameters
left
floatThe position of the left side of the rectangle on the x-axis.
top
floatThe position of the top of the rectangle on the y-axis.
right
floatThe position of the right side of the rectangle on the x-axis.
bottom
floatThe position of the bottom of the rectangle on the y-axis.
Returns
FromPoints(Vector2, Vector2)
Creates the smallest possible rectangle that contains a pair of points.
public static Rectangle FromPoints(Vector2 a, Vector2 b)
Parameters
Returns
GetAlignedPoint(Alignment)
Returns the point which aligned to the rectangle by the specified alignment.
public readonly Vector2 GetAlignedPoint(Alignment alignment)
Parameters
alignment
Alignment
Returns
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Intersects(Rectangle)
Determines if the rectangle has an intersection with another.
public bool Intersects(Rectangle other)
Parameters
other
RectangleThe rectangle to check for an intersection with.
Returns
Intersects(Rectangle, out Rectangle)
Determines if the rectangle has any intersection with another.
public bool Intersects(Rectangle other, out Rectangle overlap)
Parameters
other
RectangleThe rectangle to check for an intersection with.
overlap
RectangleThe overlapping area between the two rectangles.
Returns
SetAlignedPosition(Vector2, Alignment)
Moves the rectangle such that the provided point is at the specified position.
public void SetAlignedPosition(Vector2 position, Alignment alignment)
Parameters
position
Vector2The position to align to.
alignment
AlignmentThe point on the rectangle to align to position.
ToString()
Returns this rectangle in the format "{x, y, width, height}".
public override readonly string ToString()
Returns
Union(Rectangle)
Returns the smallest rectangle that contains both this rectangle and another.
public readonly Rectangle Union(Rectangle other)
Parameters
other
Rectangle
Returns
Operators
operator ==(Rectangle, Rectangle)
Indicates if two rectangles are equal.
public static bool operator ==(Rectangle left, Rectangle right)
Parameters
Returns
operator !=(Rectangle, Rectangle)
Indicates if two rectangles are not equal.
public static bool operator !=(Rectangle left, Rectangle right)