:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Rect2.xml. .. _class_Rect2: Rect2 ===== 2D axis-aligned bounding box. .. rst-class:: classref-introduction-group 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 :ref:`AABB`. .. rst-class:: classref-introduction-group Tutorials --------- - :doc:`Math tutorial index <../tutorials/math/index>` - :doc:`Vector math <../tutorials/math/vector_math>` - :doc:`Advanced vector math <../tutorials/math/vectors_advanced>` .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +-------------------------------+------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`end` | ``Vector2( 0, 0 )`` | +-------------------------------+------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`position` | ``Vector2( 0, 0 )`` | +-------------------------------+------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`size` | ``Vector2( 0, 0 )`` | +-------------------------------+------------------------------------------------+---------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`Rect2` **(** :ref:`Vector2` position, :ref:`Vector2` size **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`Rect2` **(** :ref:`float` x, :ref:`float` y, :ref:`float` width, :ref:`float` height **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`abs` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`clip` **(** :ref:`Rect2` b **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`encloses` **(** :ref:`Rect2` b **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`expand` **(** :ref:`Vector2` to **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_area` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_center` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`grow` **(** :ref:`float` by **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`grow_individual` **(** :ref:`float` left, :ref:`float` top, :ref:`float` right, :ref:`float` bottom **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`grow_margin` **(** :ref:`int` margin, :ref:`float` by **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_no_area` **(** **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_point` **(** :ref:`Vector2` point **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`intersects` **(** :ref:`Rect2` b, :ref:`bool` include_borders=false **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_equal_approx` **(** :ref:`Rect2` rect **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Rect2` | :ref:`merge` **(** :ref:`Rect2` b **)** | +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_Rect2_property_end: .. rst-class:: classref-property :ref:`Vector2` **end** = ``Vector2( 0, 0 )`` Ending corner. This is calculated as ``position + size``. Setting this value will change the size. .. rst-class:: classref-item-separator ---- .. _class_Rect2_property_position: .. rst-class:: classref-property :ref:`Vector2` **position** = ``Vector2( 0, 0 )`` Beginning corner. Typically has values lower than :ref:`end`. .. rst-class:: classref-item-separator ---- .. _class_Rect2_property_size: .. rst-class:: classref-property :ref:`Vector2` **size** = ``Vector2( 0, 0 )`` Size from :ref:`position` to :ref:`end`. Typically, all components are positive. If the size is negative, you can use :ref:`abs` to fix it. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_Rect2_method_Rect2: .. rst-class:: classref-method :ref:`Rect2` **Rect2** **(** :ref:`Vector2` position, :ref:`Vector2` size **)** Constructs a **Rect2** by position and size. .. rst-class:: classref-item-separator ---- .. rst-class:: classref-method :ref:`Rect2` **Rect2** **(** :ref:`float` x, :ref:`float` y, :ref:`float` width, :ref:`float` height **)** Constructs a **Rect2** by x, y, width, and height. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_abs: .. rst-class:: classref-method :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_clip: .. rst-class:: classref-method :ref:`Rect2` **clip** **(** :ref:`Rect2` b **)** Returns the intersection of this **Rect2** and b. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_encloses: .. rst-class:: classref-method :ref:`bool` **encloses** **(** :ref:`Rect2` b **)** Returns ``true`` if this **Rect2** completely encloses another one. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_expand: .. rst-class:: classref-method :ref:`Rect2` **expand** **(** :ref:`Vector2` to **)** Returns a copy of this **Rect2** expanded 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)) .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_get_area: .. rst-class:: classref-method :ref:`float` **get_area** **(** **)** Returns the area of the **Rect2**. See also :ref:`has_no_area`. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_get_center: .. rst-class:: classref-method :ref:`Vector2` **get_center** **(** **)** Returns the center of the **Rect2**, which is equal to :ref:`position` + (:ref:`size` / 2). .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_grow: .. rst-class:: classref-method :ref:`Rect2` **grow** **(** :ref:`float` by **)** Returns a copy of the **Rect2** grown a given amount of units towards all the sides. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_grow_individual: .. rst-class:: classref-method :ref:`Rect2` **grow_individual** **(** :ref:`float` left, :ref:`float` top, :ref:`float` right, :ref:`float` bottom **)** Returns a copy of the **Rect2** grown a given amount of units towards each direction individually. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_grow_margin: .. rst-class:: classref-method :ref:`Rect2` **grow_margin** **(** :ref:`int` margin, :ref:`float` by **)** Returns a copy of the **Rect2** grown a given amount of units towards the :ref:`Margin` direction. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_has_no_area: .. rst-class:: classref-method :ref:`bool` **has_no_area** **(** **)** Returns ``true`` if the **Rect2** is flat or empty, ``false`` otherwise. See also :ref:`get_area`. \ **Note:** If the **Rect2** has a negative size and is not flat or empty, :ref:`has_no_area` will return ``true``. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_has_point: .. rst-class:: classref-method :ref:`bool` **has_point** **(** :ref:`Vector2` point **)** Returns ``true`` if the **Rect2** contains a point. By convention, the right and bottom edges of the **Rect2** are considered exclusive, so points on these edges are **not** included. \ **Note:** This method is not reliable for **Rect2** with a *negative size*. Use :ref:`abs` to get a positive sized equivalent rectangle to check for contained points. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_intersects: .. rst-class:: classref-method :ref:`bool` **intersects** **(** :ref:`Rect2` b, :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_is_equal_approx: .. rst-class:: classref-method :ref:`bool` **is_equal_approx** **(** :ref:`Rect2` rect **)** Returns ``true`` if this **Rect2** and ``rect`` are approximately equal, by calling ``is_equal_approx`` on each component. .. rst-class:: classref-item-separator ---- .. _class_Rect2_method_merge: .. rst-class:: classref-method :ref:`Rect2` **merge** **(** :ref:`Rect2` b **)** Returns a larger **Rect2** that contains this **Rect2** and ``b``. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`