class_rect2i.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Rect2i.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Rect2i:
  6. Rect2i
  7. ======
  8. 2D axis-aligned bounding box using integer coordinates.
  9. Description
  10. -----------
  11. ``Rect2i`` consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
  12. It uses integer coordinates. If you need floating-point coordinates, use :ref:`Rect2<class_Rect2>` instead.
  13. Tutorials
  14. ---------
  15. - :doc:`Math documentation index <../tutorials/math/index>`
  16. - :doc:`Vector math <../tutorials/math/vector_math>`
  17. Properties
  18. ----------
  19. +---------------------------------+-------------------------------------------------+--------------------+
  20. | :ref:`Vector2i<class_Vector2i>` | :ref:`end<class_Rect2i_property_end>` | ``Vector2i(0, 0)`` |
  21. +---------------------------------+-------------------------------------------------+--------------------+
  22. | :ref:`Vector2i<class_Vector2i>` | :ref:`position<class_Rect2i_property_position>` | ``Vector2i(0, 0)`` |
  23. +---------------------------------+-------------------------------------------------+--------------------+
  24. | :ref:`Vector2i<class_Vector2i>` | :ref:`size<class_Rect2i_property_size>` | ``Vector2i(0, 0)`` |
  25. +---------------------------------+-------------------------------------------------+--------------------+
  26. Constructors
  27. ------------
  28. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** **)** |
  30. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** :ref:`Rect2i<class_Rect2i>` from **)** |
  32. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** :ref:`Rect2<class_Rect2>` from **)** |
  34. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** :ref:`Vector2i<class_Vector2i>` position, :ref:`Vector2i<class_Vector2i>` size **)** |
  36. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` width, :ref:`int<class_int>` height **)** |
  38. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. Methods
  40. -------
  41. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Rect2i<class_Rect2i>` | :ref:`abs<class_Rect2i_method_abs>` **(** **)** |const| |
  43. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`encloses<class_Rect2i_method_encloses>` **(** :ref:`Rect2i<class_Rect2i>` b **)** |const| |
  45. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Rect2i<class_Rect2i>` | :ref:`expand<class_Rect2i_method_expand>` **(** :ref:`Vector2i<class_Vector2i>` to **)** |const| |
  47. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`get_area<class_Rect2i_method_get_area>` **(** **)** |const| |
  49. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Vector2i<class_Vector2i>` | :ref:`get_center<class_Rect2i_method_get_center>` **(** **)** |const| |
  51. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Rect2i<class_Rect2i>` | :ref:`grow<class_Rect2i_method_grow>` **(** :ref:`int<class_int>` amount **)** |const| |
  53. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Rect2i<class_Rect2i>` | :ref:`grow_individual<class_Rect2i_method_grow_individual>` **(** :ref:`int<class_int>` left, :ref:`int<class_int>` top, :ref:`int<class_int>` right, :ref:`int<class_int>` bottom **)** |const| |
  55. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Rect2i<class_Rect2i>` | :ref:`grow_side<class_Rect2i_method_grow_side>` **(** :ref:`int<class_int>` side, :ref:`int<class_int>` amount **)** |const| |
  57. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`has_no_area<class_Rect2i_method_has_no_area>` **(** **)** |const| |
  59. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`bool<class_bool>` | :ref:`has_point<class_Rect2i_method_has_point>` **(** :ref:`Vector2i<class_Vector2i>` point **)** |const| |
  61. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Rect2i<class_Rect2i>` | :ref:`intersection<class_Rect2i_method_intersection>` **(** :ref:`Rect2i<class_Rect2i>` b **)** |const| |
  63. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`bool<class_bool>` | :ref:`intersects<class_Rect2i_method_intersects>` **(** :ref:`Rect2i<class_Rect2i>` b **)** |const| |
  65. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`Rect2i<class_Rect2i>` | :ref:`merge<class_Rect2i_method_merge>` **(** :ref:`Rect2i<class_Rect2i>` b **)** |const| |
  67. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. Operators
  69. ---------
  70. +-------------------------+--------------------------------------------------------------------------------------------------+
  71. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Rect2i_operator_neq_bool>` **(** **)** |
  72. +-------------------------+--------------------------------------------------------------------------------------------------+
  73. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Rect2i_operator_neq_bool>` **(** :ref:`Rect2i<class_Rect2i>` right **)** |
  74. +-------------------------+--------------------------------------------------------------------------------------------------+
  75. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Rect2i_operator_eq_bool>` **(** **)** |
  76. +-------------------------+--------------------------------------------------------------------------------------------------+
  77. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Rect2i_operator_eq_bool>` **(** :ref:`Rect2i<class_Rect2i>` right **)** |
  78. +-------------------------+--------------------------------------------------------------------------------------------------+
  79. Property Descriptions
  80. ---------------------
  81. .. _class_Rect2i_property_end:
  82. - :ref:`Vector2i<class_Vector2i>` **end**
  83. +-----------+--------------------+
  84. | *Default* | ``Vector2i(0, 0)`` |
  85. +-----------+--------------------+
  86. Ending corner. This is calculated as ``position + size``. Setting this value will change the size.
  87. ----
  88. .. _class_Rect2i_property_position:
  89. - :ref:`Vector2i<class_Vector2i>` **position**
  90. +-----------+--------------------+
  91. | *Default* | ``Vector2i(0, 0)`` |
  92. +-----------+--------------------+
  93. Beginning corner. Typically has values lower than :ref:`end<class_Rect2i_property_end>`.
  94. ----
  95. .. _class_Rect2i_property_size:
  96. - :ref:`Vector2i<class_Vector2i>` **size**
  97. +-----------+--------------------+
  98. | *Default* | ``Vector2i(0, 0)`` |
  99. +-----------+--------------------+
  100. Size from :ref:`position<class_Rect2i_property_position>` to :ref:`end<class_Rect2i_property_end>`. Typically, all components are positive.
  101. If the size is negative, you can use :ref:`abs<class_Rect2i_method_abs>` to fix it.
  102. Constructor Descriptions
  103. ------------------------
  104. .. _class_Rect2i_constructor_Rect2i:
  105. - :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** **)**
  106. Constructs a default-initialized ``Rect2i`` with default (zero) values of :ref:`position<class_Rect2i_property_position>` and :ref:`size<class_Rect2i_property_size>`.
  107. ----
  108. - :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** :ref:`Rect2i<class_Rect2i>` from **)**
  109. Constructs a ``Rect2i`` as a copy of the given ``Rect2i``.
  110. ----
  111. - :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** :ref:`Rect2<class_Rect2>` from **)**
  112. Constructs a new ``Rect2i`` from :ref:`Rect2<class_Rect2>`. The floating point coordinates will be truncated.
  113. ----
  114. - :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** :ref:`Vector2i<class_Vector2i>` position, :ref:`Vector2i<class_Vector2i>` size **)**
  115. Constructs a ``Rect2i`` by position and size.
  116. ----
  117. - :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`int<class_int>` width, :ref:`int<class_int>` height **)**
  118. Constructs a ``Rect2i`` by x, y, width, and height.
  119. Method Descriptions
  120. -------------------
  121. .. _class_Rect2i_method_abs:
  122. - :ref:`Rect2i<class_Rect2i>` **abs** **(** **)** |const|
  123. Returns a ``Rect2i`` with equivalent position and area, modified so that the top-left corner is the origin and ``width`` and ``height`` are positive.
  124. ----
  125. .. _class_Rect2i_method_encloses:
  126. - :ref:`bool<class_bool>` **encloses** **(** :ref:`Rect2i<class_Rect2i>` b **)** |const|
  127. Returns ``true`` if this ``Rect2i`` completely encloses another one.
  128. ----
  129. .. _class_Rect2i_method_expand:
  130. - :ref:`Rect2i<class_Rect2i>` **expand** **(** :ref:`Vector2i<class_Vector2i>` to **)** |const|
  131. Returns a copy of this ``Rect2i`` expanded to include a given point.
  132. .. tabs::
  133. .. code-tab:: gdscript
  134. # position (-3, 2), size (1, 1)
  135. var rect = Rect2i(Vector2i(-3, 2), Vector2i(1, 1))
  136. # position (-3, -1), size (3, 4), so we fit both rect and Vector2i(0, -1)
  137. var rect2 = rect.expand(Vector2i(0, -1))
  138. .. code-tab:: csharp
  139. # position (-3, 2), size (1, 1)
  140. var rect = new Rect2i(new Vector2i(-3, 2), new Vector2i(1, 1));
  141. # position (-3, -1), size (3, 4), so we fit both rect and Vector2i(0, -1)
  142. var rect2 = rect.Expand(new Vector2i(0, -1));
  143. ----
  144. .. _class_Rect2i_method_get_area:
  145. - :ref:`int<class_int>` **get_area** **(** **)** |const|
  146. Returns the area of the ``Rect2i``.
  147. ----
  148. .. _class_Rect2i_method_get_center:
  149. - :ref:`Vector2i<class_Vector2i>` **get_center** **(** **)** |const|
  150. Returns the center of the ``Rect2i``, which is equal to :ref:`position<class_Rect2i_property_position>` + (:ref:`size<class_Rect2i_property_size>` / 2).
  151. If :ref:`size<class_Rect2i_property_size>` is an odd number, the returned center value will be rounded towards :ref:`position<class_Rect2i_property_position>`.
  152. ----
  153. .. _class_Rect2i_method_grow:
  154. - :ref:`Rect2i<class_Rect2i>` **grow** **(** :ref:`int<class_int>` amount **)** |const|
  155. Returns a copy of the ``Rect2i`` grown by the specified ``amount`` on all sides.
  156. ----
  157. .. _class_Rect2i_method_grow_individual:
  158. - :ref:`Rect2i<class_Rect2i>` **grow_individual** **(** :ref:`int<class_int>` left, :ref:`int<class_int>` top, :ref:`int<class_int>` right, :ref:`int<class_int>` bottom **)** |const|
  159. Returns a copy of the ``Rect2i`` grown by the specified amount on each side individually.
  160. ----
  161. .. _class_Rect2i_method_grow_side:
  162. - :ref:`Rect2i<class_Rect2i>` **grow_side** **(** :ref:`int<class_int>` side, :ref:`int<class_int>` amount **)** |const|
  163. Returns a copy of the ``Rect2i`` grown by the specified ``amount`` on the specified :ref:`Side<enum_@GlobalScope_Side>`.
  164. ----
  165. .. _class_Rect2i_method_has_no_area:
  166. - :ref:`bool<class_bool>` **has_no_area** **(** **)** |const|
  167. Returns ``true`` if the ``Rect2i`` is flat or empty.
  168. ----
  169. .. _class_Rect2i_method_has_point:
  170. - :ref:`bool<class_bool>` **has_point** **(** :ref:`Vector2i<class_Vector2i>` point **)** |const|
  171. Returns ``true`` if the ``Rect2i`` contains a point. By convention, the right and bottom edges of the ``Rect2i`` are considered exclusive, so points on these edges are **not** included.
  172. **Note:** This method is not reliable for ``Rect2i`` with a *negative size*. Use :ref:`abs<class_Rect2i_method_abs>` to get a positive sized equivalent rectangle to check for contained points.
  173. ----
  174. .. _class_Rect2i_method_intersection:
  175. - :ref:`Rect2i<class_Rect2i>` **intersection** **(** :ref:`Rect2i<class_Rect2i>` b **)** |const|
  176. Returns the intersection of this ``Rect2i`` and ``b``.
  177. If the rectangles do not intersect, an empty ``Rect2i`` is returned.
  178. ----
  179. .. _class_Rect2i_method_intersects:
  180. - :ref:`bool<class_bool>` **intersects** **(** :ref:`Rect2i<class_Rect2i>` b **)** |const|
  181. Returns ``true`` if the ``Rect2i`` overlaps with ``b`` (i.e. they have at least one point in common).
  182. If ``include_borders`` is ``true``, they will also be considered overlapping if their borders touch, even without intersection.
  183. ----
  184. .. _class_Rect2i_method_merge:
  185. - :ref:`Rect2i<class_Rect2i>` **merge** **(** :ref:`Rect2i<class_Rect2i>` b **)** |const|
  186. Returns a larger ``Rect2i`` that contains this ``Rect2i`` and ``b``.
  187. Operator Descriptions
  188. ---------------------
  189. .. _class_Rect2i_operator_neq_bool:
  190. - :ref:`bool<class_bool>` **operator !=** **(** **)**
  191. ----
  192. - :ref:`bool<class_bool>` **operator !=** **(** :ref:`Rect2i<class_Rect2i>` right **)**
  193. Returns ``true`` if the rectangles are not equal.
  194. ----
  195. .. _class_Rect2i_operator_eq_bool:
  196. - :ref:`bool<class_bool>` **operator ==** **(** **)**
  197. ----
  198. - :ref:`bool<class_bool>` **operator ==** **(** :ref:`Rect2i<class_Rect2i>` right **)**
  199. Returns ``true`` if the rectangles are equal.
  200. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  201. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  202. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  203. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  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.)`
  205. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`