Table of Contents

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

position Vector2I

The position.

size Vector2I

The size.

Rect2I(Vector2I, int, int)

Constructs a Rect2I from a position, width, and height.

public Rect2I(Vector2I position, int width, int height)

Parameters

position Vector2I

The position.

width int

The width.

height int

The height.

Rect2I(int, int, Vector2I)

Constructs a Rect2I from x, y, and size.

public Rect2I(int x, int y, Vector2I size)

Parameters

x int

The position's X coordinate.

y int

The position's Y coordinate.

size Vector2I

The size.

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 int

The position's X coordinate.

y int

The position's Y coordinate.

width int

The width.

height int

The height.

Properties

Area

The area of this Rect2I. See also HasArea().

public readonly int Area { get; }

Property Value

int

End

Ending corner. This is calculated as Position plus Size. Setting this value will change the size.

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

Rect2I

The modified Rect2I.

Encloses(Rect2I)

Returns true if this Rect2I completely encloses another one.

public readonly bool Encloses(Rect2I b)

Parameters

b Rect2I

The other Rect2I that may be enclosed.

Returns

bool

A bool for whether or not this Rect2I encloses b.

Equals(Rect2I)

Returns true if this rect and other are equal.

public readonly bool Equals(Rect2I other)

Parameters

other Rect2I

The 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 object

The 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 Vector2I

The point to include.

Returns

Rect2I

The expanded Rect2I.

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 int

The amount to grow by.

Returns

Rect2I

The grown Rect2I.

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 int

The amount to grow by on the left side.

top int

The amount to grow by on the top side.

right int

The amount to grow by on the right side.

bottom int

The amount to grow by on the bottom side.

Returns

Rect2I

The grown Rect2I.

See Also

GrowSide(Side, int)

Returns a copy of the Rect2I grown by the specified amount on the specified Side.

public readonly Rect2I GrowSide(Side side, int by)

Parameters

side Side

The side to grow.

by int

The amount to grow by.

Returns

Rect2I

The grown Rect2I.

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

bool

A bool for whether or not the Rect2I has area.

HasPoint(Vector2I)

Returns true if the Rect2I contains a point, or false otherwise.

public readonly bool HasPoint(Vector2I point)

Parameters

point Vector2I

The point to check.

Returns

bool

A bool for whether or not the Rect2I contains point.

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

b Rect2I

The other Rect2I.

Returns

Rect2I

The intersection of this Rect2I and b, or an empty Rect2I if they do not intersect.

Intersects(Rect2I)

Returns true if the Rect2I overlaps with b (i.e. they have at least one point in common).

public readonly bool Intersects(Rect2I b)

Parameters

b Rect2I

The other Rect2I to check for intersections with.

Returns

bool

A bool for whether or not they are intersecting.

Merge(Rect2I)

Returns a larger Rect2I that contains this Rect2I and b.

public readonly Rect2I Merge(Rect2I b)

Parameters

b Rect2I

The other Rect2I.

Returns

Rect2I

The merged Rect2I.

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)

Returns true if the Rect2Is are exactly equal.

public static bool operator ==(Rect2I left, Rect2I right)

Parameters

left Rect2I

The left rect.

right Rect2I

The right rect.

Returns

bool

Whether or not the rects are equal.

explicit operator Rect2I(Rect2)

Converts a Rect2 to a Rect2I.

public static explicit operator Rect2I(Rect2 value)

Parameters

value Rect2

The rect to convert.

Returns

Rect2I

implicit operator Rect2(Rect2I)

Converts this Rect2I to a Rect2.

public static implicit operator Rect2(Rect2I value)

Parameters

value Rect2I

The rect to convert.

Returns

Rect2

operator !=(Rect2I, Rect2I)

Returns true if the Rect2Is are not equal.

public static bool operator !=(Rect2I left, Rect2I right)

Parameters

left Rect2I

The left rect.

right Rect2I

The right rect.

Returns

bool

Whether or not the rects are not equal.