class_rect2.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Rect2.xml.
  6. .. _class_Rect2:
  7. Rect2
  8. =====
  9. 2D axis-aligned bounding box.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. **Rect2** consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
  14. It uses floating-point coordinates.
  15. The 3D counterpart to **Rect2** is :ref:`AABB<class_AABB>`.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Math tutorial index <../tutorials/math/index>`
  20. - :doc:`Vector math <../tutorials/math/vector_math>`
  21. - :doc:`Advanced vector math <../tutorials/math/vectors_advanced>`
  22. .. rst-class:: classref-reftable-group
  23. Properties
  24. ----------
  25. .. table::
  26. :widths: auto
  27. +-------------------------------+------------------------------------------------+---------------------+
  28. | :ref:`Vector2<class_Vector2>` | :ref:`end<class_Rect2_property_end>` | ``Vector2( 0, 0 )`` |
  29. +-------------------------------+------------------------------------------------+---------------------+
  30. | :ref:`Vector2<class_Vector2>` | :ref:`position<class_Rect2_property_position>` | ``Vector2( 0, 0 )`` |
  31. +-------------------------------+------------------------------------------------+---------------------+
  32. | :ref:`Vector2<class_Vector2>` | :ref:`size<class_Rect2_property_size>` | ``Vector2( 0, 0 )`` |
  33. +-------------------------------+------------------------------------------------+---------------------+
  34. .. rst-class:: classref-reftable-group
  35. Methods
  36. -------
  37. .. table::
  38. :widths: auto
  39. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Rect2<class_Rect2>` | :ref:`Rect2<class_Rect2_method_Rect2>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`Vector2<class_Vector2>` size **)** |
  41. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Rect2<class_Rect2>` | :ref:`Rect2<class_Rect2_method_Rect2>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` width, :ref:`float<class_float>` height **)** |
  43. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`Rect2<class_Rect2>` | :ref:`abs<class_Rect2_method_abs>` **(** **)** |
  45. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Rect2<class_Rect2>` | :ref:`clip<class_Rect2_method_clip>` **(** :ref:`Rect2<class_Rect2>` b **)** |
  47. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`encloses<class_Rect2_method_encloses>` **(** :ref:`Rect2<class_Rect2>` b **)** |
  49. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Rect2<class_Rect2>` | :ref:`expand<class_Rect2_method_expand>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  51. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`float<class_float>` | :ref:`get_area<class_Rect2_method_get_area>` **(** **)** |
  53. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Vector2<class_Vector2>` | :ref:`get_center<class_Rect2_method_get_center>` **(** **)** |
  55. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Rect2<class_Rect2>` | :ref:`grow<class_Rect2_method_grow>` **(** :ref:`float<class_float>` by **)** |
  57. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Rect2<class_Rect2>` | :ref:`grow_individual<class_Rect2_method_grow_individual>` **(** :ref:`float<class_float>` left, :ref:`float<class_float>` top, :ref:`float<class_float>` right, :ref:`float<class_float>` bottom **)** |
  59. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`Rect2<class_Rect2>` | :ref:`grow_margin<class_Rect2_method_grow_margin>` **(** :ref:`int<class_int>` margin, :ref:`float<class_float>` by **)** |
  61. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`bool<class_bool>` | :ref:`has_no_area<class_Rect2_method_has_no_area>` **(** **)** |
  63. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`has_point<class_Rect2_method_has_point>` **(** :ref:`Vector2<class_Vector2>` point **)** |
  65. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`bool<class_bool>` | :ref:`intersects<class_Rect2_method_intersects>` **(** :ref:`Rect2<class_Rect2>` b, :ref:`bool<class_bool>` include_borders=false **)** |
  67. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Rect2_method_is_equal_approx>` **(** :ref:`Rect2<class_Rect2>` rect **)** |
  69. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Rect2<class_Rect2>` | :ref:`merge<class_Rect2_method_merge>` **(** :ref:`Rect2<class_Rect2>` b **)** |
  71. +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. .. rst-class:: classref-section-separator
  73. ----
  74. .. rst-class:: classref-descriptions-group
  75. Property Descriptions
  76. ---------------------
  77. .. _class_Rect2_property_end:
  78. .. rst-class:: classref-property
  79. :ref:`Vector2<class_Vector2>` **end** = ``Vector2( 0, 0 )``
  80. Ending corner. This is calculated as ``position + size``. Setting this value will change the size.
  81. .. rst-class:: classref-item-separator
  82. ----
  83. .. _class_Rect2_property_position:
  84. .. rst-class:: classref-property
  85. :ref:`Vector2<class_Vector2>` **position** = ``Vector2( 0, 0 )``
  86. Beginning corner. Typically has values lower than :ref:`end<class_Rect2_property_end>`.
  87. .. rst-class:: classref-item-separator
  88. ----
  89. .. _class_Rect2_property_size:
  90. .. rst-class:: classref-property
  91. :ref:`Vector2<class_Vector2>` **size** = ``Vector2( 0, 0 )``
  92. Size from :ref:`position<class_Rect2_property_position>` to :ref:`end<class_Rect2_property_end>`. Typically, all components are positive.
  93. If the size is negative, you can use :ref:`abs<class_Rect2_method_abs>` to fix it.
  94. .. rst-class:: classref-section-separator
  95. ----
  96. .. rst-class:: classref-descriptions-group
  97. Method Descriptions
  98. -------------------
  99. .. _class_Rect2_method_Rect2:
  100. .. rst-class:: classref-method
  101. :ref:`Rect2<class_Rect2>` **Rect2** **(** :ref:`Vector2<class_Vector2>` position, :ref:`Vector2<class_Vector2>` size **)**
  102. Constructs a **Rect2** by position and size.
  103. .. rst-class:: classref-item-separator
  104. ----
  105. .. rst-class:: classref-method
  106. :ref:`Rect2<class_Rect2>` **Rect2** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` width, :ref:`float<class_float>` height **)**
  107. Constructs a **Rect2** by x, y, width, and height.
  108. .. rst-class:: classref-item-separator
  109. ----
  110. .. _class_Rect2_method_abs:
  111. .. rst-class:: classref-method
  112. :ref:`Rect2<class_Rect2>` **abs** **(** **)**
  113. Returns a **Rect2** with equivalent position and area, modified so that the top-left corner is the origin and ``width`` and ``height`` are positive.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_Rect2_method_clip:
  117. .. rst-class:: classref-method
  118. :ref:`Rect2<class_Rect2>` **clip** **(** :ref:`Rect2<class_Rect2>` b **)**
  119. Returns the intersection of this **Rect2** and b.
  120. .. rst-class:: classref-item-separator
  121. ----
  122. .. _class_Rect2_method_encloses:
  123. .. rst-class:: classref-method
  124. :ref:`bool<class_bool>` **encloses** **(** :ref:`Rect2<class_Rect2>` b **)**
  125. Returns ``true`` if this **Rect2** completely encloses another one.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_Rect2_method_expand:
  129. .. rst-class:: classref-method
  130. :ref:`Rect2<class_Rect2>` **expand** **(** :ref:`Vector2<class_Vector2>` to **)**
  131. Returns a copy of this **Rect2** expanded to include a given point.
  132. \ **Example:**\
  133. ::
  134. # position (-3, 2), size (1, 1)
  135. var rect = Rect2(Vector2(-3, 2), Vector2(1, 1))
  136. # position (-3, -1), size (3, 4), so we fit both rect and Vector2(0, -1)
  137. var rect2 = rect.expand(Vector2(0, -1))
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_Rect2_method_get_area:
  141. .. rst-class:: classref-method
  142. :ref:`float<class_float>` **get_area** **(** **)**
  143. Returns the area of the **Rect2**. See also :ref:`has_no_area<class_Rect2_method_has_no_area>`.
  144. .. rst-class:: classref-item-separator
  145. ----
  146. .. _class_Rect2_method_get_center:
  147. .. rst-class:: classref-method
  148. :ref:`Vector2<class_Vector2>` **get_center** **(** **)**
  149. Returns the center of the **Rect2**, which is equal to :ref:`position<class_Rect2_property_position>` + (:ref:`size<class_Rect2_property_size>` / 2).
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_Rect2_method_grow:
  153. .. rst-class:: classref-method
  154. :ref:`Rect2<class_Rect2>` **grow** **(** :ref:`float<class_float>` by **)**
  155. Returns a copy of the **Rect2** grown a given amount of units towards all the sides.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_Rect2_method_grow_individual:
  159. .. rst-class:: classref-method
  160. :ref:`Rect2<class_Rect2>` **grow_individual** **(** :ref:`float<class_float>` left, :ref:`float<class_float>` top, :ref:`float<class_float>` right, :ref:`float<class_float>` bottom **)**
  161. Returns a copy of the **Rect2** grown a given amount of units towards each direction individually.
  162. .. rst-class:: classref-item-separator
  163. ----
  164. .. _class_Rect2_method_grow_margin:
  165. .. rst-class:: classref-method
  166. :ref:`Rect2<class_Rect2>` **grow_margin** **(** :ref:`int<class_int>` margin, :ref:`float<class_float>` by **)**
  167. Returns a copy of the **Rect2** grown a given amount of units towards the :ref:`Margin<enum_@GlobalScope_Margin>` direction.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_Rect2_method_has_no_area:
  171. .. rst-class:: classref-method
  172. :ref:`bool<class_bool>` **has_no_area** **(** **)**
  173. Returns ``true`` if the **Rect2** is flat or empty, ``false`` otherwise. See also :ref:`get_area<class_Rect2_method_get_area>`.
  174. \ **Note:** If the **Rect2** has a negative size and is not flat or empty, :ref:`has_no_area<class_Rect2_method_has_no_area>` will return ``true``.
  175. .. rst-class:: classref-item-separator
  176. ----
  177. .. _class_Rect2_method_has_point:
  178. .. rst-class:: classref-method
  179. :ref:`bool<class_bool>` **has_point** **(** :ref:`Vector2<class_Vector2>` point **)**
  180. 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.
  181. \ **Note:** This method is not reliable for **Rect2** with a *negative size*. Use :ref:`abs<class_Rect2_method_abs>` to get a positive sized equivalent rectangle to check for contained points.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _class_Rect2_method_intersects:
  185. .. rst-class:: classref-method
  186. :ref:`bool<class_bool>` **intersects** **(** :ref:`Rect2<class_Rect2>` b, :ref:`bool<class_bool>` include_borders=false **)**
  187. Returns ``true`` if the **Rect2** overlaps with ``b`` (i.e. they have at least one point in common).
  188. If ``include_borders`` is ``true``, they will also be considered overlapping if their borders touch, even without intersection.
  189. .. rst-class:: classref-item-separator
  190. ----
  191. .. _class_Rect2_method_is_equal_approx:
  192. .. rst-class:: classref-method
  193. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Rect2<class_Rect2>` rect **)**
  194. Returns ``true`` if this **Rect2** and ``rect`` are approximately equal, by calling ``is_equal_approx`` on each component.
  195. .. rst-class:: classref-item-separator
  196. ----
  197. .. _class_Rect2_method_merge:
  198. .. rst-class:: classref-method
  199. :ref:`Rect2<class_Rect2>` **merge** **(** :ref:`Rect2<class_Rect2>` b **)**
  200. Returns a larger **Rect2** that contains this **Rect2** and ``b``.
  201. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  202. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  203. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  204. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`