Rect2
2D axis-aligned bounding box.
Description
Rect2 consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
It uses floating-point coordinates.
The 3D counterpart to Rect2 is AABB.
Tutorials
Properties
| ||
| ||
|
Methods
abs ( ) | |
get_area ( ) | |
grow_individual ( float left, float top, float right, float bottom ) | |
grow_margin ( int margin, float by ) | |
has_no_area ( ) | |
intersects ( Rect2 b, bool include_borders=false ) | |
is_equal_approx ( Rect2 rect ) | |
Property Descriptions
Vector2 end
Default |
|
Ending corner. This is calculated as position + size. Setting this value will change the size.
Vector2 position
Default |
|
Beginning corner. Typically has values lower than end.
Vector2 size
Default |
|
Size from position to end. Typically, all components are positive.
If the size is negative, you can use abs to fix it.
Method Descriptions
Rect2 Rect2 ( Vector2 position, Vector2 size )
Constructs a Rect2 by position and size.
Constructs a Rect2 by x, y, width, and height.
Rect2 abs ( )
Returns a Rect2 with equivalent position and area, modified so that the top-left corner is the origin and width and height are positive.
Returns the intersection of this Rect2 and b.
Returns true if this Rect2 completely encloses another one.
Returns this Rect2 expanded to include a given point.
float get_area ( )
Returns the area of the Rect2.
Returns a copy of the Rect2 grown a given amount of units towards all the sides.
Rect2 grow_individual ( float left, float top, float right, float bottom )
Returns a copy of the Rect2 grown a given amount of units towards each direction individually.
Rect2 grow_margin ( int margin, float by )
Returns a copy of the Rect2 grown a given amount of units towards the Margin direction.
bool has_no_area ( )
Returns true if the Rect2 is flat or empty.
bool has_point ( Vector2 point )
Returns true if the Rect2 contains a point.
bool intersects ( Rect2 b, bool include_borders=false )
Returns true if the Rect2 overlaps with b (i.e. they have at least one point in common).
If include_borders is true, they will also be considered overlapping if their borders touch, even without intersection.
bool is_equal_approx ( Rect2 rect )
Returns true if this Rect2 and rect are approximately equal, by calling is_equal_approx on each component.
Returns a larger Rect2 that contains this Rect2 and b.
© 2014–2021 Juan Linietsky, Ariel Manzur, Godot Engine contributors
Licensed under the MIT License.
https://docs.godotengine.org/en/3.3/classes/class_rect2.html