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
staticinlineop_Equality(left:Rect2, right:Rect2):Bool
Operator overload for godot.Rect2
== godot.Rect2
.
staticinlineop_Inequality(left:Rect2, right:Rect2):Bool
Operator overload for godot.Rect2
!= godot.Rect2
.
Constructor
Variables
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
position:Vector2
Beginning corner. Typically has values lower than godot.Rect2.end
.
Value: Directly uses a private field.
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
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
.
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 |
---|
Returns:
The clipped godot.Rect2
.
encloses(b:Rect2):Bool
Returns true
if this godot.Rect2
completely encloses another one.
Parameters:
b | The other |
---|
Returns:
A bool
for whether or not this godot.Rect2
encloses b
.
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
.
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:
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:
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:
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.
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
.
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 |
---|---|
includeBorders | Whether or not to consider borders. |
Returns:
A bool
for whether or not they are intersecting.
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.
merge(b:Rect2):Rect2
Returns a larger godot.Rect2
that contains this godot.Rect2
and b
.
Parameters:
b | The other |
---|
Returns:
The merged godot.Rect2
.