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.
Rect2 is AABB.
Tutorials
- Math tutorial index
- Vector math
- Advanced vector math
Properties
Methods
Property Descriptions
- Vector2 end
position + size. Setting this value will change the size.
- Vector2 position end.
- Vector2 size
position to end. Typically, all components are positive.
abs to fix it.
Method Descriptions
- Rect2 Rect2 ( Vector2 position, Vector2 size )
Rect2by position and size.
- Rect2 Rect2 ( float x, float y, float width, float height )
Rect2by x, y, width, and height.
- Rect2 abs ( )
Rect2with equivalent position and area, modified so that the top-left corner is the origin andwidthandheightare positive.
- Rect2 clip ( Rect2 b )
Rect2and b.
- bool encloses ( Rect2 b )
trueif thisRect2completely encloses another one.
- Rect2 expand ( Vector2 to )
Rect2expanded to include a given point. Example:# position (-3, 2), size (1, 1)var rect = Rect2(Vector2(-3, 2), Vector2(1, 1))# position (-3, -1), size (3, 4), so we fit both rect and Vector2(0, -1)var rect2 = rect.expand(Vector2(0, -1))
- float get_area ( )
Rect2. See also has_no_area.
- Vector2 get_center ( )
Rect2, which is equal to position + (size / 2).
- Rect2 grow ( float by )
Rect2grown a given amount of units towards all the sides.
- Rect2 grow_individual ( float left, float top, float right, float bottom )
Rect2grown a given amount of units towards each direction individually.
- Rect2 grow_margin ( int margin, float by )
Rect2grown a given amount of units towards the Margin direction.
- bool has_no_area ( )
trueif theRect2is flat or empty,falseotherwise. See also get_area. Note: If theRect2has a negative size and is not flat or empty, has_no_area will returntrue.
- bool has_point ( Vector2 point )
trueif theRect2contains a point. By convention, the right and bottom edges of theRect2are considered exclusive, so points on these edges are not included. Note: This method is not reliable forRect2with a negative size. Use abs to get a positive sized equivalent rectangle to check for contained points.
- bool intersects ( Rect2 b, bool include_borders=false )
trueif theRect2overlaps withb(i.e. they have at least one point in common).include_bordersistrue, they will also be considered overlapping if their borders touch, even without intersection.
- bool is_equal_approx ( Rect2 rect )
trueif thisRect2andrectare approximately equal, by callingis_equal_approxon each component.
- Rect2 merge ( Rect2 b )
Rect2that contains thisRect2andb.
