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 toRect2 isAABB.
Tutorials¶
Properties¶
| ||
| ||
|
Methods¶
abs() | |
get_area() | |
grow_individual(float left,float top,float right,float bottom) | |
grow_margin(int margin,float by) | |
intersects(Rect2 b,bool include_borders=false) | |
is_equal_approx(Rect2 rect) | |
Property Descriptions¶
Vector2end
Default |
|
Ending corner. This is calculated asposition+size. Setting this value will change the size.
Vector2position
Default |
|
Beginning corner. Typically has values lower thanend.
Vector2size
Default |
|
Size fromposition toend. Typically, all components are positive.
If the size is negative, you can useabs to fix it.
Method Descriptions¶
Constructs aRect2 by position and size.
Constructs aRect2 by x, y, width, and height.
Rect2abs()
Returns aRect2 with equivalent position and area, modified so that the top-left corner is the origin andwidth andheight are positive.
Returns the intersection of thisRect2 and b.
Returnstrue if thisRect2 completely encloses another one.
Returns a copy of thisRect2 expanded to include a given point.
Example:
# position (-3, 2), size (1, 1)varrect=Rect2(Vector2(-3,2),Vector2(1,1))# position (-3, -1), size (3, 4), so we fit both rect and Vector2(0, -1)varrect2=rect.expand(Vector2(0,-1))
floatget_area()
Returns the area of theRect2. See alsohas_no_area.
Returns a copy of theRect2 grown a given amount of units towards all the sides.
Returns a copy of theRect2 grown a given amount of units towards each direction individually.
Returns a copy of theRect2 grown a given amount of units towards theMargin direction.
boolhas_no_area()
Returnstrue if theRect2 is flat or empty,false otherwise. See alsoget_area.
Note: If theRect2 has a negative size and is not flat or empty,has_no_area will returntrue.
Returnstrue if theRect2 contains a point. By convention, the right and bottom edges of theRect2 are considered exclusive, so points on these edges arenot included.
Note: This method is not reliable forRect2 with anegative size. Useabs to get a positive sized equivalent rectangle to check for contained points.
Returnstrue if theRect2 overlaps withb (i.e. they have at least one point in common).
Ifinclude_borders istrue, they will also be considered overlapping if their borders touch, even without intersection.
Returnstrue if thisRect2 andrect are approximately equal, by callingis_equal_approx on each component.
Returns a largerRect2 that contains thisRect2 andb.