class_rect2i.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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/4.1/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.1/doc/classes/Rect2i.xml.
  6. .. _class_Rect2i:
  7. Rect2i
  8. ======
  9. A 2D axis-aligned bounding box using integer coordinates.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. **Rect2i** consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
  14. It uses integer coordinates. If you need floating-point coordinates, use :ref:`Rect2<class_Rect2>` instead.
  15. Negative values for :ref:`size<class_Rect2i_property_size>` are not supported and will not work for most methods. Use :ref:`abs<class_Rect2i_method_abs>` to get a Rect2i with a positive size.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Math documentation index <../tutorials/math/index>`
  20. - :doc:`Vector math <../tutorials/math/vector_math>`
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +---------------------------------+-------------------------------------------------+--------------------+
  27. | :ref:`Vector2i<class_Vector2i>` | :ref:`end<class_Rect2i_property_end>` | ``Vector2i(0, 0)`` |
  28. +---------------------------------+-------------------------------------------------+--------------------+
  29. | :ref:`Vector2i<class_Vector2i>` | :ref:`position<class_Rect2i_property_position>` | ``Vector2i(0, 0)`` |
  30. +---------------------------------+-------------------------------------------------+--------------------+
  31. | :ref:`Vector2i<class_Vector2i>` | :ref:`size<class_Rect2i_property_size>` | ``Vector2i(0, 0)`` |
  32. +---------------------------------+-------------------------------------------------+--------------------+
  33. .. rst-class:: classref-reftable-group
  34. Constructors
  35. ------------
  36. .. table::
  37. :widths: auto
  38. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** **)** |
  40. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** :ref:`Rect2i<class_Rect2i>` from **)** |
  42. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** :ref:`Rect2<class_Rect2>` from **)** |
  44. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Rect2i<class_Rect2i>` | :ref:`Rect2i<class_Rect2i_constructor_Rect2i>` **(** :ref:`Vector2i<class_Vector2i>` position, :ref:`Vector2i<class_Vector2i>` size **)** |
  46. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :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 **)** |
  48. +-----------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. .. rst-class:: classref-reftable-group
  50. Methods
  51. -------
  52. .. table::
  53. :widths: auto
  54. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Rect2i<class_Rect2i>` | :ref:`abs<class_Rect2i_method_abs>` **(** **)** |const| |
  56. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`encloses<class_Rect2i_method_encloses>` **(** :ref:`Rect2i<class_Rect2i>` b **)** |const| |
  58. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Rect2i<class_Rect2i>` | :ref:`expand<class_Rect2i_method_expand>` **(** :ref:`Vector2i<class_Vector2i>` to **)** |const| |
  60. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`int<class_int>` | :ref:`get_area<class_Rect2i_method_get_area>` **(** **)** |const| |
  62. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Vector2i<class_Vector2i>` | :ref:`get_center<class_Rect2i_method_get_center>` **(** **)** |const| |
  64. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Rect2i<class_Rect2i>` | :ref:`grow<class_Rect2i_method_grow>` **(** :ref:`int<class_int>` amount **)** |const| |
  66. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :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| |
  68. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`Rect2i<class_Rect2i>` | :ref:`grow_side<class_Rect2i_method_grow_side>` **(** :ref:`int<class_int>` side, :ref:`int<class_int>` amount **)** |const| |
  70. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`bool<class_bool>` | :ref:`has_area<class_Rect2i_method_has_area>` **(** **)** |const| |
  72. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`bool<class_bool>` | :ref:`has_point<class_Rect2i_method_has_point>` **(** :ref:`Vector2i<class_Vector2i>` point **)** |const| |
  74. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Rect2i<class_Rect2i>` | :ref:`intersection<class_Rect2i_method_intersection>` **(** :ref:`Rect2i<class_Rect2i>` b **)** |const| |
  76. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`bool<class_bool>` | :ref:`intersects<class_Rect2i_method_intersects>` **(** :ref:`Rect2i<class_Rect2i>` b **)** |const| |
  78. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Rect2i<class_Rect2i>` | :ref:`merge<class_Rect2i_method_merge>` **(** :ref:`Rect2i<class_Rect2i>` b **)** |const| |
  80. +---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. .. rst-class:: classref-reftable-group
  82. Operators
  83. ---------
  84. .. table::
  85. :widths: auto
  86. +-------------------------+----------------------------------------------------------------------------------------------------+
  87. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Rect2i_operator_neq_Rect2i>` **(** :ref:`Rect2i<class_Rect2i>` right **)** |
  88. +-------------------------+----------------------------------------------------------------------------------------------------+
  89. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Rect2i_operator_eq_Rect2i>` **(** :ref:`Rect2i<class_Rect2i>` right **)** |
  90. +-------------------------+----------------------------------------------------------------------------------------------------+
  91. .. rst-class:: classref-section-separator
  92. ----
  93. .. rst-class:: classref-descriptions-group
  94. Property Descriptions
  95. ---------------------
  96. .. _class_Rect2i_property_end:
  97. .. rst-class:: classref-property
  98. :ref:`Vector2i<class_Vector2i>` **end** = ``Vector2i(0, 0)``
  99. Ending corner. This is calculated as ``position + size``. Setting this value will change the size.
  100. .. rst-class:: classref-item-separator
  101. ----
  102. .. _class_Rect2i_property_position:
  103. .. rst-class:: classref-property
  104. :ref:`Vector2i<class_Vector2i>` **position** = ``Vector2i(0, 0)``
  105. Beginning corner. Typically has values lower than :ref:`end<class_Rect2i_property_end>`.
  106. .. rst-class:: classref-item-separator
  107. ----
  108. .. _class_Rect2i_property_size:
  109. .. rst-class:: classref-property
  110. :ref:`Vector2i<class_Vector2i>` **size** = ``Vector2i(0, 0)``
  111. Size from :ref:`position<class_Rect2i_property_position>` to :ref:`end<class_Rect2i_property_end>`. Typically, all components are positive.
  112. If the size is negative, you can use :ref:`abs<class_Rect2i_method_abs>` to fix it.
  113. .. rst-class:: classref-section-separator
  114. ----
  115. .. rst-class:: classref-descriptions-group
  116. Constructor Descriptions
  117. ------------------------
  118. .. _class_Rect2i_constructor_Rect2i:
  119. .. rst-class:: classref-constructor
  120. :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** **)**
  121. Constructs a default-initialized **Rect2i** with default (zero) values of :ref:`position<class_Rect2i_property_position>` and :ref:`size<class_Rect2i_property_size>`.
  122. .. rst-class:: classref-item-separator
  123. ----
  124. .. rst-class:: classref-constructor
  125. :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** :ref:`Rect2i<class_Rect2i>` from **)**
  126. Constructs a **Rect2i** as a copy of the given **Rect2i**.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. rst-class:: classref-constructor
  130. :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** :ref:`Rect2<class_Rect2>` from **)**
  131. Constructs a new **Rect2i** from :ref:`Rect2<class_Rect2>`. The floating point coordinates will be truncated.
  132. .. rst-class:: classref-item-separator
  133. ----
  134. .. rst-class:: classref-constructor
  135. :ref:`Rect2i<class_Rect2i>` **Rect2i** **(** :ref:`Vector2i<class_Vector2i>` position, :ref:`Vector2i<class_Vector2i>` size **)**
  136. Constructs a **Rect2i** by position and size.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. rst-class:: classref-constructor
  140. :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 **)**
  141. Constructs a **Rect2i** by x, y, width, and height.
  142. .. rst-class:: classref-section-separator
  143. ----
  144. .. rst-class:: classref-descriptions-group
  145. Method Descriptions
  146. -------------------
  147. .. _class_Rect2i_method_abs:
  148. .. rst-class:: classref-method
  149. :ref:`Rect2i<class_Rect2i>` **abs** **(** **)** |const|
  150. Returns a **Rect2i** with equivalent position and area, modified so that the top-left corner is the origin and ``width`` and ``height`` are positive.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_Rect2i_method_encloses:
  154. .. rst-class:: classref-method
  155. :ref:`bool<class_bool>` **encloses** **(** :ref:`Rect2i<class_Rect2i>` b **)** |const|
  156. Returns ``true`` if this **Rect2i** completely encloses another one.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_Rect2i_method_expand:
  160. .. rst-class:: classref-method
  161. :ref:`Rect2i<class_Rect2i>` **expand** **(** :ref:`Vector2i<class_Vector2i>` to **)** |const|
  162. Returns a copy of this **Rect2i** expanded so that the borders align with the given point.
  163. .. tabs::
  164. .. code-tab:: gdscript
  165. # position (-3, 2), size (1, 1)
  166. var rect = Rect2i(Vector2i(-3, 2), Vector2i(1, 1))
  167. # position (-3, -1), size (3, 4), so we fit both rect and Vector2i(0, -1)
  168. var rect2 = rect.expand(Vector2i(0, -1))
  169. .. code-tab:: csharp
  170. // position (-3, 2), size (1, 1)
  171. var rect = new Rect2I(new Vector2I(-3, 2), new Vector2I(1, 1));
  172. // position (-3, -1), size (3, 4), so we fit both rect and Vector2I(0, -1)
  173. var rect2 = rect.Expand(new Vector2I(0, -1));
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_Rect2i_method_get_area:
  177. .. rst-class:: classref-method
  178. :ref:`int<class_int>` **get_area** **(** **)** |const|
  179. Returns the area of the **Rect2i**. See also :ref:`has_area<class_Rect2i_method_has_area>`.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_Rect2i_method_get_center:
  183. .. rst-class:: classref-method
  184. :ref:`Vector2i<class_Vector2i>` **get_center** **(** **)** |const|
  185. Returns the center of the **Rect2i**, which is equal to :ref:`position<class_Rect2i_property_position>` + (:ref:`size<class_Rect2i_property_size>` / 2).
  186. 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>`.
  187. .. rst-class:: classref-item-separator
  188. ----
  189. .. _class_Rect2i_method_grow:
  190. .. rst-class:: classref-method
  191. :ref:`Rect2i<class_Rect2i>` **grow** **(** :ref:`int<class_int>` amount **)** |const|
  192. Returns a copy of the **Rect2i** grown by the specified ``amount`` on all sides.
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. _class_Rect2i_method_grow_individual:
  196. .. rst-class:: classref-method
  197. :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|
  198. Returns a copy of the **Rect2i** grown by the specified amount on each side individually.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_Rect2i_method_grow_side:
  202. .. rst-class:: classref-method
  203. :ref:`Rect2i<class_Rect2i>` **grow_side** **(** :ref:`int<class_int>` side, :ref:`int<class_int>` amount **)** |const|
  204. Returns a copy of the **Rect2i** grown by the specified ``amount`` on the specified :ref:`Side<enum_@GlobalScope_Side>`.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. _class_Rect2i_method_has_area:
  208. .. rst-class:: classref-method
  209. :ref:`bool<class_bool>` **has_area** **(** **)** |const|
  210. Returns ``true`` if the **Rect2i** has area, and ``false`` if the **Rect2i** is linear, empty, or has a negative :ref:`size<class_Rect2i_property_size>`. See also :ref:`get_area<class_Rect2i_method_get_area>`.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_Rect2i_method_has_point:
  214. .. rst-class:: classref-method
  215. :ref:`bool<class_bool>` **has_point** **(** :ref:`Vector2i<class_Vector2i>` point **)** |const|
  216. 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.
  217. \ **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.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_Rect2i_method_intersection:
  221. .. rst-class:: classref-method
  222. :ref:`Rect2i<class_Rect2i>` **intersection** **(** :ref:`Rect2i<class_Rect2i>` b **)** |const|
  223. Returns the intersection of this **Rect2i** and ``b``.
  224. If the rectangles do not intersect, an empty **Rect2i** is returned.
  225. .. rst-class:: classref-item-separator
  226. ----
  227. .. _class_Rect2i_method_intersects:
  228. .. rst-class:: classref-method
  229. :ref:`bool<class_bool>` **intersects** **(** :ref:`Rect2i<class_Rect2i>` b **)** |const|
  230. Returns ``true`` if the **Rect2i** overlaps with ``b`` (i.e. they have at least one point in common).
  231. .. rst-class:: classref-item-separator
  232. ----
  233. .. _class_Rect2i_method_merge:
  234. .. rst-class:: classref-method
  235. :ref:`Rect2i<class_Rect2i>` **merge** **(** :ref:`Rect2i<class_Rect2i>` b **)** |const|
  236. Returns a larger **Rect2i** that contains this **Rect2i** and ``b``.
  237. .. rst-class:: classref-section-separator
  238. ----
  239. .. rst-class:: classref-descriptions-group
  240. Operator Descriptions
  241. ---------------------
  242. .. _class_Rect2i_operator_neq_Rect2i:
  243. .. rst-class:: classref-operator
  244. :ref:`bool<class_bool>` **operator !=** **(** :ref:`Rect2i<class_Rect2i>` right **)**
  245. Returns ``true`` if the rectangles are not equal.
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_Rect2i_operator_eq_Rect2i:
  249. .. rst-class:: classref-operator
  250. :ref:`bool<class_bool>` **operator ==** **(** :ref:`Rect2i<class_Rect2i>` right **)**
  251. Returns ``true`` if the rectangles are equal.
  252. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  253. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  254. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  255. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  256. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  257. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  258. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`