class_rect2.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Rect2.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Rect2:
  6. Rect2
  7. =====
  8. 2D axis-aligned bounding box.
  9. Description
  10. -----------
  11. ``Rect2`` consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
  12. It uses floating-point coordinates.
  13. The 3D counterpart to ``Rect2`` is :ref:`AABB<class_AABB>`.
  14. Tutorials
  15. ---------
  16. - :doc:`../tutorials/math/index`
  17. - :doc:`../tutorials/math/vector_math`
  18. - :doc:`../tutorials/math/vectors_advanced`
  19. Properties
  20. ----------
  21. +-------------------------------+------------------------------------------------+---------------------+
  22. | :ref:`Vector2<class_Vector2>` | :ref:`end<class_Rect2_property_end>` | ``Vector2( 0, 0 )`` |
  23. +-------------------------------+------------------------------------------------+---------------------+
  24. | :ref:`Vector2<class_Vector2>` | :ref:`position<class_Rect2_property_position>` | ``Vector2( 0, 0 )`` |
  25. +-------------------------------+------------------------------------------------+---------------------+
  26. | :ref:`Vector2<class_Vector2>` | :ref:`size<class_Rect2_property_size>` | ``Vector2( 0, 0 )`` |
  27. +-------------------------------+------------------------------------------------+---------------------+
  28. Methods
  29. -------
  30. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Rect2<class_Rect2>` | :ref:`Rect2<class_Rect2_method_Rect2>` **(** :ref:`Vector2<class_Vector2>` position, :ref:`Vector2<class_Vector2>` size **)** |
  32. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :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 **)** |
  34. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Rect2<class_Rect2>` | :ref:`abs<class_Rect2_method_abs>` **(** **)** |
  36. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Rect2<class_Rect2>` | :ref:`clip<class_Rect2_method_clip>` **(** :ref:`Rect2<class_Rect2>` b **)** |
  38. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`encloses<class_Rect2_method_encloses>` **(** :ref:`Rect2<class_Rect2>` b **)** |
  40. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Rect2<class_Rect2>` | :ref:`expand<class_Rect2_method_expand>` **(** :ref:`Vector2<class_Vector2>` to **)** |
  42. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`float<class_float>` | :ref:`get_area<class_Rect2_method_get_area>` **(** **)** |
  44. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Rect2<class_Rect2>` | :ref:`grow<class_Rect2_method_grow>` **(** :ref:`float<class_float>` by **)** |
  46. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :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 **)** |
  48. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Rect2<class_Rect2>` | :ref:`grow_margin<class_Rect2_method_grow_margin>` **(** :ref:`int<class_int>` margin, :ref:`float<class_float>` by **)** |
  50. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`has_no_area<class_Rect2_method_has_no_area>` **(** **)** |
  52. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`has_point<class_Rect2_method_has_point>` **(** :ref:`Vector2<class_Vector2>` point **)** |
  54. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`intersects<class_Rect2_method_intersects>` **(** :ref:`Rect2<class_Rect2>` b, :ref:`bool<class_bool>` include_borders=false **)** |
  56. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Rect2_method_is_equal_approx>` **(** :ref:`Rect2<class_Rect2>` rect **)** |
  58. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Rect2<class_Rect2>` | :ref:`merge<class_Rect2_method_merge>` **(** :ref:`Rect2<class_Rect2>` b **)** |
  60. +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. Property Descriptions
  62. ---------------------
  63. .. _class_Rect2_property_end:
  64. - :ref:`Vector2<class_Vector2>` **end**
  65. +-----------+---------------------+
  66. | *Default* | ``Vector2( 0, 0 )`` |
  67. +-----------+---------------------+
  68. Ending corner. This is calculated as ``position + size``. Setting this value will change the size.
  69. ----
  70. .. _class_Rect2_property_position:
  71. - :ref:`Vector2<class_Vector2>` **position**
  72. +-----------+---------------------+
  73. | *Default* | ``Vector2( 0, 0 )`` |
  74. +-----------+---------------------+
  75. Beginning corner. Typically has values lower than :ref:`end<class_Rect2_property_end>`.
  76. ----
  77. .. _class_Rect2_property_size:
  78. - :ref:`Vector2<class_Vector2>` **size**
  79. +-----------+---------------------+
  80. | *Default* | ``Vector2( 0, 0 )`` |
  81. +-----------+---------------------+
  82. Size from :ref:`position<class_Rect2_property_position>` to :ref:`end<class_Rect2_property_end>`. Typically, all components are positive.
  83. If the size is negative, you can use :ref:`abs<class_Rect2_method_abs>` to fix it.
  84. Method Descriptions
  85. -------------------
  86. .. _class_Rect2_method_Rect2:
  87. - :ref:`Rect2<class_Rect2>` **Rect2** **(** :ref:`Vector2<class_Vector2>` position, :ref:`Vector2<class_Vector2>` size **)**
  88. Constructs a ``Rect2`` by position and size.
  89. ----
  90. - :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 **)**
  91. Constructs a ``Rect2`` by x, y, width, and height.
  92. ----
  93. .. _class_Rect2_method_abs:
  94. - :ref:`Rect2<class_Rect2>` **abs** **(** **)**
  95. Returns a ``Rect2`` with equivalent position and area, modified so that the top-left corner is the origin and ``width`` and ``height`` are positive.
  96. ----
  97. .. _class_Rect2_method_clip:
  98. - :ref:`Rect2<class_Rect2>` **clip** **(** :ref:`Rect2<class_Rect2>` b **)**
  99. Returns the intersection of this ``Rect2`` and b.
  100. ----
  101. .. _class_Rect2_method_encloses:
  102. - :ref:`bool<class_bool>` **encloses** **(** :ref:`Rect2<class_Rect2>` b **)**
  103. Returns ``true`` if this ``Rect2`` completely encloses another one.
  104. ----
  105. .. _class_Rect2_method_expand:
  106. - :ref:`Rect2<class_Rect2>` **expand** **(** :ref:`Vector2<class_Vector2>` to **)**
  107. Returns this ``Rect2`` expanded to include a given point.
  108. ----
  109. .. _class_Rect2_method_get_area:
  110. - :ref:`float<class_float>` **get_area** **(** **)**
  111. Returns the area of the ``Rect2``.
  112. ----
  113. .. _class_Rect2_method_grow:
  114. - :ref:`Rect2<class_Rect2>` **grow** **(** :ref:`float<class_float>` by **)**
  115. Returns a copy of the ``Rect2`` grown a given amount of units towards all the sides.
  116. ----
  117. .. _class_Rect2_method_grow_individual:
  118. - :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 **)**
  119. Returns a copy of the ``Rect2`` grown a given amount of units towards each direction individually.
  120. ----
  121. .. _class_Rect2_method_grow_margin:
  122. - :ref:`Rect2<class_Rect2>` **grow_margin** **(** :ref:`int<class_int>` margin, :ref:`float<class_float>` by **)**
  123. Returns a copy of the ``Rect2`` grown a given amount of units towards the :ref:`Margin<enum_@GlobalScope_Margin>` direction.
  124. ----
  125. .. _class_Rect2_method_has_no_area:
  126. - :ref:`bool<class_bool>` **has_no_area** **(** **)**
  127. Returns ``true`` if the ``Rect2`` is flat or empty.
  128. ----
  129. .. _class_Rect2_method_has_point:
  130. - :ref:`bool<class_bool>` **has_point** **(** :ref:`Vector2<class_Vector2>` point **)**
  131. Returns ``true`` if the ``Rect2`` contains a point.
  132. ----
  133. .. _class_Rect2_method_intersects:
  134. - :ref:`bool<class_bool>` **intersects** **(** :ref:`Rect2<class_Rect2>` b, :ref:`bool<class_bool>` include_borders=false **)**
  135. Returns ``true`` if the ``Rect2`` overlaps with ``b`` (i.e. they have at least one point in common).
  136. If ``include_borders`` is ``true``, they will also be considered overlapping if their borders touch, even without intersection.
  137. ----
  138. .. _class_Rect2_method_is_equal_approx:
  139. - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Rect2<class_Rect2>` rect **)**
  140. Returns ``true`` if this ``Rect2`` and ``rect`` are approximately equal, by calling ``is_equal_approx`` on each component.
  141. ----
  142. .. _class_Rect2_method_merge:
  143. - :ref:`Rect2<class_Rect2>` **merge** **(** :ref:`Rect2<class_Rect2>` b **)**
  144. Returns a larger ``Rect2`` that contains this ``Rect2`` and ``b``.
  145. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  146. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  147. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`