Struct Rect2I
- Namespace
- Godot
- Assembly
- GodotSharp.dll
2D axis-aligned bounding box using integers. Rect2I consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
public struct Rect2I : IEquatable<Rect2I>
- Implements
- Inherited Members
Constructors
Rect2I(Vector2I, Vector2I)
Constructs a Rect2I from a position and size.
public Rect2I(Vector2I position, Vector2I size)
Parameters
Rect2I(Vector2I, int, int)
Constructs a Rect2I from a position, width, and height.
public Rect2I(Vector2I position, int width, int height)
Parameters
Rect2I(int, int, Vector2I)
Constructs a Rect2I from x, y, and size.
public Rect2I(int x, int y, Vector2I size)
Parameters
Rect2I(int, int, int, int)
Constructs a Rect2I from x, y, width, and height.
public Rect2I(int x, int y, int width, int height)
Parameters
x
intThe position's X coordinate.
y
intThe position's Y coordinate.
width
intThe width.
height
intThe height.
Properties
Area
public readonly int Area { get; }
Property Value
End
public Vector2I End { readonly get; set; }
Property Value
- Vector2I
Getting is equivalent to
value
= Position + Size, setting is equivalent to Size =value
- Position
Position
Beginning corner. Typically has values lower than End.
public Vector2I Position { readonly get; set; }
Property Value
- Vector2I
Directly uses a private field.
Size
Size from Position to End. Typically all components are positive. If the size is negative, you can use Abs() to fix it.
public Vector2I Size { readonly get; set; }
Property Value
- Vector2I
Directly uses a private field.
Methods
Abs()
Returns a Rect2I with equivalent position and size, modified so that the top-left corner is the origin and width and height are positive.
public readonly Rect2I Abs()
Returns
Encloses(Rect2I)
public readonly bool Encloses(Rect2I b)
Parameters
Returns
Equals(Rect2I)
Returns true if this rect and other
are equal.
public readonly bool Equals(Rect2I other)
Parameters
other
Rect2IThe other rect to compare.
Returns
- bool
Whether or not the rects are equal.
Equals(object)
Returns true if this rect and obj
are equal.
public override readonly bool Equals(object obj)
Parameters
obj
objectThe other object to compare.
Returns
- bool
Whether or not the rect and the other object are equal.
Expand(Vector2I)
Returns this Rect2I expanded to include a given point.
public readonly Rect2I Expand(Vector2I to)
Parameters
to
Vector2IThe point to include.
Returns
GetCenter()
Returns the center of the Rect2I, which is equal to Position + (Size / 2). If Size is an odd number, the returned center value will be rounded towards Position.
public readonly Vector2I GetCenter()
Returns
- Vector2I
The center.
GetHashCode()
Serves as the hash function for Rect2I.
public override readonly int GetHashCode()
Returns
- int
A hash code for this rect.
Grow(int)
Returns a copy of the Rect2I grown by the specified amount on all sides.
public readonly Rect2I Grow(int by)
Parameters
by
intThe amount to grow by.
Returns
- See Also
GrowIndividual(int, int, int, int)
Returns a copy of the Rect2I grown by the specified amount on each side individually.
public readonly Rect2I GrowIndividual(int left, int top, int right, int bottom)
Parameters
left
intThe amount to grow by on the left side.
top
intThe amount to grow by on the top side.
right
intThe amount to grow by on the right side.
bottom
intThe amount to grow by on the bottom side.
Returns
- See Also
GrowSide(Side, int)
public readonly Rect2I GrowSide(Side side, int by)
Parameters
Returns
- See Also
HasArea()
Returns true if the Rect2I has area, and false if the Rect2I is linear, empty, or has a negative Size. See also Area.
public readonly bool HasArea()
Returns
HasPoint(Vector2I)
public readonly bool HasPoint(Vector2I point)
Parameters
point
Vector2IThe point to check.
Returns
Intersection(Rect2I)
Returns the intersection of this Rect2I and b
.
If the rectangles do not intersect, an empty Rect2I is returned.
public readonly Rect2I Intersection(Rect2I b)
Parameters
Returns
Intersects(Rect2I)
public readonly bool Intersects(Rect2I b)
Parameters
Returns
Merge(Rect2I)
public readonly Rect2I Merge(Rect2I b)
Parameters
Returns
ToString()
Converts this Rect2I to a string.
public override readonly string ToString()
Returns
- string
A string representation of this rect.
ToString(string)
Converts this Rect2I to a string with the given format
.
public readonly string ToString(string format)
Parameters
format
string
Returns
- string
A string representation of this rect.
Operators
operator ==(Rect2I, Rect2I)
public static bool operator ==(Rect2I left, Rect2I right)
Parameters
Returns
- bool
Whether or not the rects are equal.
explicit operator Rect2I(Rect2)
public static explicit operator Rect2I(Rect2 value)
Parameters
value
Rect2The rect to convert.
Returns
implicit operator Rect2(Rect2I)
public static implicit operator Rect2(Rect2I value)
Parameters
value
Rect2IThe rect to convert.
Returns
operator !=(Rect2I, Rect2I)
public static bool operator !=(Rect2I left, Rect2I right)
Parameters
Returns
- bool
Whether or not the rects are not equal.