2D axis-aligned bounding box. Rect2 consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.

Static methods

@:op(A == B)staticinlineop_Equality(left:Rect2, right:Rect2):Bool

Operator overload for godot.Rect2 == godot.Rect2.

@:op(A != B)staticinlineop_Inequality(left:Rect2, right:Rect2):Bool

Operator overload for godot.Rect2 != godot.Rect2.

Constructor

@:native("new")new(position:Vector2, size:Vector2)

@:native("new")new(x:Single, y:Single, width:Single, height:Single)

@:native("new")new(x:Single, y:Single, size:Vector2)

@:native("new")new(position:Vector2, width:Single, height:Single)

Constructs a godot.Rect2 from a position and size.

Parameters:

position

The position.

size

The size.

Variables

@:native("Area")read onlyarea:Single

The area of this godot.Rect2.

Value: Equivalent to godot.Rect2.getArea.

@:native("End")end:Vector2

Ending corner. This is calculated as godot.Rect2.position plus godot.Rect2.size. Setting this value will change the size.

Value: Getting is equivalent to value = godot.Rect2.position + godot.Rect2.size, setting is equivalent to godot.Rect2.size = value - godot.Rect2.position

@:native("Position")position:Vector2

Beginning corner. Typically has values lower than godot.Rect2.end.

Value: Directly uses a private field.

@:native("Size")size:Vector2

Size from godot.Rect2.position to godot.Rect2.end. Typically all components are positive. If the size is negative, you can use godot.Rect2.abs to fix it.

Value: Directly uses a private field.

Methods

@:native("Abs")abs():Rect2

Returns a godot.Rect2 with equivalent position and size, modified so that the top-left corner is the origin and width and height are positive.

Returns:

The modified godot.Rect2.

@:native("Clip")clip(b:Rect2):Rect2

Returns the intersection of this godot.Rect2 and b. If the rectangles do not intersect, an empty godot.Rect2 is returned.

Parameters:

b

The other godot.Rect2.

Returns:

The clipped godot.Rect2.

@:native("Encloses")encloses(b:Rect2):Bool

Returns true if this godot.Rect2 completely encloses another one.

Parameters:

b

The other godot.Rect2 that may be enclosed.

Returns:

A bool for whether or not this godot.Rect2 encloses b.

@:native("Expand")expand(to:Vector2):Rect2

Returns this godot.Rect2 expanded to include a given point.

Parameters:

to

The point to include.

Returns:

The expanded godot.Rect2.

@:native("GetArea")getArea():Single

Returns the area of the godot.Rect2.

Returns:

The area.

@:native("Grow")grow(by:Single):Rect2

Returns a copy of the godot.Rect2 grown a given amount of units towards all the sides. @see godot.Rect2.growMargin

Parameters:

by

The amount to grow by.

Returns:

The grown godot.Rect2.

See also:

@:native("GrowIndividual")growIndividual(left:Single, top:Single, right:Single, bottom:Single):Rect2

Returns a copy of the godot.Rect2 grown a given amount of units towards each direction individually. @see godot.Rect2.growMargin

Parameters:

left

The amount to grow by on the left.

top

The amount to grow by on the top.

right

The amount to grow by on the right.

bottom

The amount to grow by on the bottom.

Returns:

The grown godot.Rect2.

See also:

@:native("GrowMargin")growMargin(margin:Margin, by:Single):Rect2

Returns a copy of the godot.Rect2 grown a given amount of units towards the godot.Margin direction. @see godot.Rect2.growIndividual

Parameters:

margin

The direction to grow in.

by

The amount to grow by.

Returns:

The grown godot.Rect2.

See also:

@:native("HasNoArea")hasNoArea():Bool

Returns true if the godot.Rect2 is flat or empty, or false otherwise.

Returns:

A bool for whether or not the godot.Rect2 has area.

@:native("HasPoint")hasPoint(point:Vector2):Bool

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

Parameters:

point

The point to check.

Returns:

A bool for whether or not the godot.Rect2 contains point.

@:native("Intersects")intersects(b:Rect2, ?includeBorders:Bool):Bool

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

If includeBorders is true, they will also be considered overlapping if their borders touch, even without intersection.

Parameters:

b

The other godot.Rect2 to check for intersections with.

includeBorders

Whether or not to consider borders.

Returns:

A bool for whether or not they are intersecting.

@:native("IsEqualApprox")isEqualApprox(other:Rect2):Bool

Returns true if this rect and other are approximately equal, by running godot.Vector2.isEqualApprox on each component.

Parameters:

other

The other rect to compare.

Returns:

Whether or not the rects are approximately equal.

@:native("Merge")merge(b:Rect2):Rect2

Returns a larger godot.Rect2 that contains this godot.Rect2 and b.

Parameters:

b

The other godot.Rect2.

Returns:

The merged godot.Rect2.

@:native("ToString")toString():String

@:native("ToString")ToString(format:String):String

Converts this godot.Rect2 to a string.

Returns:

A string representation of this rect.