class_geometry2d.rst 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Geometry2D.xml.
  6. .. _class_Geometry2D:
  7. Geometry2D
  8. ==========
  9. **Inherits:** :ref:`Object<class_Object>`
  10. Provides methods for some common 2D geometric operations.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Provides a set of helper functions to create geometric shapes, compute intersections between shapes, and process various other geometric operations in 2D.
  15. .. rst-class:: classref-reftable-group
  16. Methods
  17. -------
  18. .. table::
  19. :widths: auto
  20. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`clip_polygons<class_Geometry2D_method_clip_polygons>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_a, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_b **)** |
  22. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`clip_polyline_with_polygon<class_Geometry2D_method_clip_polyline_with_polygon>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polyline, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)** |
  24. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`convex_hull<class_Geometry2D_method_convex_hull>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points **)** |
  26. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`decompose_polygon_in_convex<class_Geometry2D_method_decompose_polygon_in_convex>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)** |
  28. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`exclude_polygons<class_Geometry2D_method_exclude_polygons>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_a, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_b **)** |
  30. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Vector2<class_Vector2>` | :ref:`get_closest_point_to_segment<class_Geometry2D_method_get_closest_point_to_segment>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`Vector2<class_Vector2>` s1, :ref:`Vector2<class_Vector2>` s2 **)** |
  32. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Vector2<class_Vector2>` | :ref:`get_closest_point_to_segment_uncapped<class_Geometry2D_method_get_closest_point_to_segment_uncapped>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`Vector2<class_Vector2>` s1, :ref:`Vector2<class_Vector2>` s2 **)** |
  34. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_closest_points_between_segments<class_Geometry2D_method_get_closest_points_between_segments>` **(** :ref:`Vector2<class_Vector2>` p1, :ref:`Vector2<class_Vector2>` q1, :ref:`Vector2<class_Vector2>` p2, :ref:`Vector2<class_Vector2>` q2 **)** |
  36. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`intersect_polygons<class_Geometry2D_method_intersect_polygons>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_a, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_b **)** |
  38. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`intersect_polyline_with_polygon<class_Geometry2D_method_intersect_polyline_with_polygon>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polyline, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)** |
  40. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`is_point_in_circle<class_Geometry2D_method_is_point_in_circle>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`Vector2<class_Vector2>` circle_position, :ref:`float<class_float>` circle_radius **)** |
  42. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`is_point_in_polygon<class_Geometry2D_method_is_point_in_polygon>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)** |
  44. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`is_polygon_clockwise<class_Geometry2D_method_is_polygon_clockwise>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)** |
  46. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Variant<class_Variant>` | :ref:`line_intersects_line<class_Geometry2D_method_line_intersects_line>` **(** :ref:`Vector2<class_Vector2>` from_a, :ref:`Vector2<class_Vector2>` dir_a, :ref:`Vector2<class_Vector2>` from_b, :ref:`Vector2<class_Vector2>` dir_b **)** |
  48. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Dictionary<class_Dictionary>` | :ref:`make_atlas<class_Geometry2D_method_make_atlas>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` sizes **)** |
  50. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`merge_polygons<class_Geometry2D_method_merge_polygons>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_a, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_b **)** |
  52. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`offset_polygon<class_Geometry2D_method_offset_polygon>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon, :ref:`float<class_float>` delta, :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` join_type=0 **)** |
  54. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`PackedVector2Array[]<class_PackedVector2Array>` | :ref:`offset_polyline<class_Geometry2D_method_offset_polyline>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polyline, :ref:`float<class_float>` delta, :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` join_type=0, :ref:`PolyEndType<enum_Geometry2D_PolyEndType>` end_type=3 **)** |
  56. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`point_is_inside_triangle<class_Geometry2D_method_point_is_inside_triangle>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`Vector2<class_Vector2>` a, :ref:`Vector2<class_Vector2>` b, :ref:`Vector2<class_Vector2>` c **)** |const| |
  58. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`float<class_float>` | :ref:`segment_intersects_circle<class_Geometry2D_method_segment_intersects_circle>` **(** :ref:`Vector2<class_Vector2>` segment_from, :ref:`Vector2<class_Vector2>` segment_to, :ref:`Vector2<class_Vector2>` circle_position, :ref:`float<class_float>` circle_radius **)** |
  60. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Variant<class_Variant>` | :ref:`segment_intersects_segment<class_Geometry2D_method_segment_intersects_segment>` **(** :ref:`Vector2<class_Vector2>` from_a, :ref:`Vector2<class_Vector2>` to_a, :ref:`Vector2<class_Vector2>` from_b, :ref:`Vector2<class_Vector2>` to_b **)** |
  62. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`triangulate_delaunay<class_Geometry2D_method_triangulate_delaunay>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points **)** |
  64. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`triangulate_polygon<class_Geometry2D_method_triangulate_polygon>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)** |
  66. +-------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. .. rst-class:: classref-section-separator
  68. ----
  69. .. rst-class:: classref-descriptions-group
  70. Enumerations
  71. ------------
  72. .. _enum_Geometry2D_PolyBooleanOperation:
  73. .. rst-class:: classref-enumeration
  74. enum **PolyBooleanOperation**:
  75. .. _class_Geometry2D_constant_OPERATION_UNION:
  76. .. rst-class:: classref-enumeration-constant
  77. :ref:`PolyBooleanOperation<enum_Geometry2D_PolyBooleanOperation>` **OPERATION_UNION** = ``0``
  78. Create regions where either subject or clip polygons (or both) are filled.
  79. .. _class_Geometry2D_constant_OPERATION_DIFFERENCE:
  80. .. rst-class:: classref-enumeration-constant
  81. :ref:`PolyBooleanOperation<enum_Geometry2D_PolyBooleanOperation>` **OPERATION_DIFFERENCE** = ``1``
  82. Create regions where subject polygons are filled except where clip polygons are filled.
  83. .. _class_Geometry2D_constant_OPERATION_INTERSECTION:
  84. .. rst-class:: classref-enumeration-constant
  85. :ref:`PolyBooleanOperation<enum_Geometry2D_PolyBooleanOperation>` **OPERATION_INTERSECTION** = ``2``
  86. Create regions where both subject and clip polygons are filled.
  87. .. _class_Geometry2D_constant_OPERATION_XOR:
  88. .. rst-class:: classref-enumeration-constant
  89. :ref:`PolyBooleanOperation<enum_Geometry2D_PolyBooleanOperation>` **OPERATION_XOR** = ``3``
  90. Create regions where either subject or clip polygons are filled but not where both are filled.
  91. .. rst-class:: classref-item-separator
  92. ----
  93. .. _enum_Geometry2D_PolyJoinType:
  94. .. rst-class:: classref-enumeration
  95. enum **PolyJoinType**:
  96. .. _class_Geometry2D_constant_JOIN_SQUARE:
  97. .. rst-class:: classref-enumeration-constant
  98. :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` **JOIN_SQUARE** = ``0``
  99. Squaring is applied uniformally at all convex edge joins at ``1 * delta``.
  100. .. _class_Geometry2D_constant_JOIN_ROUND:
  101. .. rst-class:: classref-enumeration-constant
  102. :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` **JOIN_ROUND** = ``1``
  103. While flattened paths can never perfectly trace an arc, they are approximated by a series of arc chords.
  104. .. _class_Geometry2D_constant_JOIN_MITER:
  105. .. rst-class:: classref-enumeration-constant
  106. :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` **JOIN_MITER** = ``2``
  107. There's a necessary limit to mitered joins since offsetting edges that join at very acute angles will produce excessively long and narrow "spikes". For any given edge join, when miter offsetting would exceed that maximum distance, "square" joining is applied.
  108. .. rst-class:: classref-item-separator
  109. ----
  110. .. _enum_Geometry2D_PolyEndType:
  111. .. rst-class:: classref-enumeration
  112. enum **PolyEndType**:
  113. .. _class_Geometry2D_constant_END_POLYGON:
  114. .. rst-class:: classref-enumeration-constant
  115. :ref:`PolyEndType<enum_Geometry2D_PolyEndType>` **END_POLYGON** = ``0``
  116. Endpoints are joined using the :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` value and the path filled as a polygon.
  117. .. _class_Geometry2D_constant_END_JOINED:
  118. .. rst-class:: classref-enumeration-constant
  119. :ref:`PolyEndType<enum_Geometry2D_PolyEndType>` **END_JOINED** = ``1``
  120. Endpoints are joined using the :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` value and the path filled as a polyline.
  121. .. _class_Geometry2D_constant_END_BUTT:
  122. .. rst-class:: classref-enumeration-constant
  123. :ref:`PolyEndType<enum_Geometry2D_PolyEndType>` **END_BUTT** = ``2``
  124. Endpoints are squared off with no extension.
  125. .. _class_Geometry2D_constant_END_SQUARE:
  126. .. rst-class:: classref-enumeration-constant
  127. :ref:`PolyEndType<enum_Geometry2D_PolyEndType>` **END_SQUARE** = ``3``
  128. Endpoints are squared off and extended by ``delta`` units.
  129. .. _class_Geometry2D_constant_END_ROUND:
  130. .. rst-class:: classref-enumeration-constant
  131. :ref:`PolyEndType<enum_Geometry2D_PolyEndType>` **END_ROUND** = ``4``
  132. Endpoints are rounded off and extended by ``delta`` units.
  133. .. rst-class:: classref-section-separator
  134. ----
  135. .. rst-class:: classref-descriptions-group
  136. Method Descriptions
  137. -------------------
  138. .. _class_Geometry2D_method_clip_polygons:
  139. .. rst-class:: classref-method
  140. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **clip_polygons** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_a, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_b **)**
  141. Clips ``polygon_a`` against ``polygon_b`` and returns an array of clipped polygons. This performs :ref:`OPERATION_DIFFERENCE<class_Geometry2D_constant_OPERATION_DIFFERENCE>` between polygons. Returns an empty array if ``polygon_b`` completely overlaps ``polygon_a``.
  142. If ``polygon_b`` is enclosed by ``polygon_a``, returns an outer polygon (boundary) and inner polygon (hole) which could be distinguished by calling :ref:`is_polygon_clockwise<class_Geometry2D_method_is_polygon_clockwise>`.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_Geometry2D_method_clip_polyline_with_polygon:
  146. .. rst-class:: classref-method
  147. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **clip_polyline_with_polygon** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polyline, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)**
  148. Clips ``polyline`` against ``polygon`` and returns an array of clipped polylines. This performs :ref:`OPERATION_DIFFERENCE<class_Geometry2D_constant_OPERATION_DIFFERENCE>` between the polyline and the polygon. This operation can be thought of as cutting a line with a closed shape.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_Geometry2D_method_convex_hull:
  152. .. rst-class:: classref-method
  153. :ref:`PackedVector2Array<class_PackedVector2Array>` **convex_hull** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points **)**
  154. Given an array of :ref:`Vector2<class_Vector2>`\ s, returns the convex hull as a list of points in counterclockwise order. The last point is the same as the first one.
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_Geometry2D_method_decompose_polygon_in_convex:
  158. .. rst-class:: classref-method
  159. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **decompose_polygon_in_convex** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)**
  160. Decomposes the ``polygon`` into multiple convex hulls and returns an array of :ref:`PackedVector2Array<class_PackedVector2Array>`.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_Geometry2D_method_exclude_polygons:
  164. .. rst-class:: classref-method
  165. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **exclude_polygons** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_a, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_b **)**
  166. Mutually excludes common area defined by intersection of ``polygon_a`` and ``polygon_b`` (see :ref:`intersect_polygons<class_Geometry2D_method_intersect_polygons>`) and returns an array of excluded polygons. This performs :ref:`OPERATION_XOR<class_Geometry2D_constant_OPERATION_XOR>` between polygons. In other words, returns all but common area between polygons.
  167. The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distinguished by calling :ref:`is_polygon_clockwise<class_Geometry2D_method_is_polygon_clockwise>`.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_Geometry2D_method_get_closest_point_to_segment:
  171. .. rst-class:: classref-method
  172. :ref:`Vector2<class_Vector2>` **get_closest_point_to_segment** **(** :ref:`Vector2<class_Vector2>` point, :ref:`Vector2<class_Vector2>` s1, :ref:`Vector2<class_Vector2>` s2 **)**
  173. Returns the 2D point on the 2D segment (``s1``, ``s2``) that is closest to ``point``. The returned point will always be inside the specified segment.
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_Geometry2D_method_get_closest_point_to_segment_uncapped:
  177. .. rst-class:: classref-method
  178. :ref:`Vector2<class_Vector2>` **get_closest_point_to_segment_uncapped** **(** :ref:`Vector2<class_Vector2>` point, :ref:`Vector2<class_Vector2>` s1, :ref:`Vector2<class_Vector2>` s2 **)**
  179. Returns the 2D point on the 2D line defined by (``s1``, ``s2``) that is closest to ``point``. The returned point can be inside the segment (``s1``, ``s2``) or outside of it, i.e. somewhere on the line extending from the segment.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_Geometry2D_method_get_closest_points_between_segments:
  183. .. rst-class:: classref-method
  184. :ref:`PackedVector2Array<class_PackedVector2Array>` **get_closest_points_between_segments** **(** :ref:`Vector2<class_Vector2>` p1, :ref:`Vector2<class_Vector2>` q1, :ref:`Vector2<class_Vector2>` p2, :ref:`Vector2<class_Vector2>` q2 **)**
  185. Given the two 2D segments (``p1``, ``q1``) and (``p2``, ``q2``), finds those two points on the two segments that are closest to each other. Returns a :ref:`PackedVector2Array<class_PackedVector2Array>` that contains this point on (``p1``, ``q1``) as well the accompanying point on (``p2``, ``q2``).
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_Geometry2D_method_intersect_polygons:
  189. .. rst-class:: classref-method
  190. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **intersect_polygons** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_a, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_b **)**
  191. Intersects ``polygon_a`` with ``polygon_b`` and returns an array of intersected polygons. This performs :ref:`OPERATION_INTERSECTION<class_Geometry2D_constant_OPERATION_INTERSECTION>` between polygons. In other words, returns common area shared by polygons. Returns an empty array if no intersection occurs.
  192. The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distinguished by calling :ref:`is_polygon_clockwise<class_Geometry2D_method_is_polygon_clockwise>`.
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. _class_Geometry2D_method_intersect_polyline_with_polygon:
  196. .. rst-class:: classref-method
  197. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **intersect_polyline_with_polygon** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polyline, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)**
  198. Intersects ``polyline`` with ``polygon`` and returns an array of intersected polylines. This performs :ref:`OPERATION_INTERSECTION<class_Geometry2D_constant_OPERATION_INTERSECTION>` between the polyline and the polygon. This operation can be thought of as chopping a line with a closed shape.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_Geometry2D_method_is_point_in_circle:
  202. .. rst-class:: classref-method
  203. :ref:`bool<class_bool>` **is_point_in_circle** **(** :ref:`Vector2<class_Vector2>` point, :ref:`Vector2<class_Vector2>` circle_position, :ref:`float<class_float>` circle_radius **)**
  204. Returns ``true`` if ``point`` is inside the circle or if it's located exactly *on* the circle's boundary, otherwise returns ``false``.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. _class_Geometry2D_method_is_point_in_polygon:
  208. .. rst-class:: classref-method
  209. :ref:`bool<class_bool>` **is_point_in_polygon** **(** :ref:`Vector2<class_Vector2>` point, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)**
  210. Returns ``true`` if ``point`` is inside ``polygon`` or if it's located exactly *on* polygon's boundary, otherwise returns ``false``.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_Geometry2D_method_is_polygon_clockwise:
  214. .. rst-class:: classref-method
  215. :ref:`bool<class_bool>` **is_polygon_clockwise** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)**
  216. Returns ``true`` if ``polygon``'s vertices are ordered in clockwise order, otherwise returns ``false``.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_Geometry2D_method_line_intersects_line:
  220. .. rst-class:: classref-method
  221. :ref:`Variant<class_Variant>` **line_intersects_line** **(** :ref:`Vector2<class_Vector2>` from_a, :ref:`Vector2<class_Vector2>` dir_a, :ref:`Vector2<class_Vector2>` from_b, :ref:`Vector2<class_Vector2>` dir_b **)**
  222. Checks if the two lines (``from_a``, ``dir_a``) and (``from_b``, ``dir_b``) intersect. If yes, return the point of intersection as :ref:`Vector2<class_Vector2>`. If no intersection takes place, returns ``null``.
  223. \ **Note:** The lines are specified using direction vectors, not end points.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_Geometry2D_method_make_atlas:
  227. .. rst-class:: classref-method
  228. :ref:`Dictionary<class_Dictionary>` **make_atlas** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` sizes **)**
  229. Given an array of :ref:`Vector2<class_Vector2>`\ s representing tiles, builds an atlas. The returned dictionary has two keys: ``points`` is a :ref:`PackedVector2Array<class_PackedVector2Array>` that specifies the positions of each tile, ``size`` contains the overall size of the whole atlas as :ref:`Vector2i<class_Vector2i>`.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_Geometry2D_method_merge_polygons:
  233. .. rst-class:: classref-method
  234. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **merge_polygons** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_a, :ref:`PackedVector2Array<class_PackedVector2Array>` polygon_b **)**
  235. Merges (combines) ``polygon_a`` and ``polygon_b`` and returns an array of merged polygons. This performs :ref:`OPERATION_UNION<class_Geometry2D_constant_OPERATION_UNION>` between polygons.
  236. The operation may result in an outer polygon (boundary) and multiple inner polygons (holes) produced which could be distinguished by calling :ref:`is_polygon_clockwise<class_Geometry2D_method_is_polygon_clockwise>`.
  237. .. rst-class:: classref-item-separator
  238. ----
  239. .. _class_Geometry2D_method_offset_polygon:
  240. .. rst-class:: classref-method
  241. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **offset_polygon** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon, :ref:`float<class_float>` delta, :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` join_type=0 **)**
  242. Inflates or deflates ``polygon`` by ``delta`` units (pixels). If ``delta`` is positive, makes the polygon grow outward. If ``delta`` is negative, shrinks the polygon inward. Returns an array of polygons because inflating/deflating may result in multiple discrete polygons. Returns an empty array if ``delta`` is negative and the absolute value of it approximately exceeds the minimum bounding rectangle dimensions of the polygon.
  243. Each polygon's vertices will be rounded as determined by ``join_type``, see :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>`.
  244. The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distinguished by calling :ref:`is_polygon_clockwise<class_Geometry2D_method_is_polygon_clockwise>`.
  245. \ **Note:** To translate the polygon's vertices specifically, multiply them to a :ref:`Transform2D<class_Transform2D>`:
  246. .. tabs::
  247. .. code-tab:: gdscript
  248. var polygon = PackedVector2Array([Vector2(0, 0), Vector2(100, 0), Vector2(100, 100), Vector2(0, 100)])
  249. var offset = Vector2(50, 50)
  250. polygon = Transform2D(0, offset) * polygon
  251. print(polygon) # prints [(50, 50), (150, 50), (150, 150), (50, 150)]
  252. .. code-tab:: csharp
  253. var polygon = new Vector2[] { new Vector2(0, 0), new Vector2(100, 0), new Vector2(100, 100), new Vector2(0, 100) };
  254. var offset = new Vector2(50, 50);
  255. polygon = new Transform2D(0, offset) * polygon;
  256. GD.Print((Variant)polygon); // prints [(50, 50), (150, 50), (150, 150), (50, 150)]
  257. .. rst-class:: classref-item-separator
  258. ----
  259. .. _class_Geometry2D_method_offset_polyline:
  260. .. rst-class:: classref-method
  261. :ref:`PackedVector2Array[]<class_PackedVector2Array>` **offset_polyline** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polyline, :ref:`float<class_float>` delta, :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>` join_type=0, :ref:`PolyEndType<enum_Geometry2D_PolyEndType>` end_type=3 **)**
  262. Inflates or deflates ``polyline`` by ``delta`` units (pixels), producing polygons. If ``delta`` is positive, makes the polyline grow outward. Returns an array of polygons because inflating/deflating may result in multiple discrete polygons. If ``delta`` is negative, returns an empty array.
  263. Each polygon's vertices will be rounded as determined by ``join_type``, see :ref:`PolyJoinType<enum_Geometry2D_PolyJoinType>`.
  264. Each polygon's endpoints will be rounded as determined by ``end_type``, see :ref:`PolyEndType<enum_Geometry2D_PolyEndType>`.
  265. The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distinguished by calling :ref:`is_polygon_clockwise<class_Geometry2D_method_is_polygon_clockwise>`.
  266. .. rst-class:: classref-item-separator
  267. ----
  268. .. _class_Geometry2D_method_point_is_inside_triangle:
  269. .. rst-class:: classref-method
  270. :ref:`bool<class_bool>` **point_is_inside_triangle** **(** :ref:`Vector2<class_Vector2>` point, :ref:`Vector2<class_Vector2>` a, :ref:`Vector2<class_Vector2>` b, :ref:`Vector2<class_Vector2>` c **)** |const|
  271. Returns if ``point`` is inside the triangle specified by ``a``, ``b`` and ``c``.
  272. .. rst-class:: classref-item-separator
  273. ----
  274. .. _class_Geometry2D_method_segment_intersects_circle:
  275. .. rst-class:: classref-method
  276. :ref:`float<class_float>` **segment_intersects_circle** **(** :ref:`Vector2<class_Vector2>` segment_from, :ref:`Vector2<class_Vector2>` segment_to, :ref:`Vector2<class_Vector2>` circle_position, :ref:`float<class_float>` circle_radius **)**
  277. Given the 2D segment (``segment_from``, ``segment_to``), returns the position on the segment (as a number between 0 and 1) at which the segment hits the circle that is located at position ``circle_position`` and has radius ``circle_radius``. If the segment does not intersect the circle, -1 is returned (this is also the case if the line extending the segment would intersect the circle, but the segment does not).
  278. .. rst-class:: classref-item-separator
  279. ----
  280. .. _class_Geometry2D_method_segment_intersects_segment:
  281. .. rst-class:: classref-method
  282. :ref:`Variant<class_Variant>` **segment_intersects_segment** **(** :ref:`Vector2<class_Vector2>` from_a, :ref:`Vector2<class_Vector2>` to_a, :ref:`Vector2<class_Vector2>` from_b, :ref:`Vector2<class_Vector2>` to_b **)**
  283. Checks if the two segments (``from_a``, ``to_a``) and (``from_b``, ``to_b``) intersect. If yes, return the point of intersection as :ref:`Vector2<class_Vector2>`. If no intersection takes place, returns ``null``.
  284. .. rst-class:: classref-item-separator
  285. ----
  286. .. _class_Geometry2D_method_triangulate_delaunay:
  287. .. rst-class:: classref-method
  288. :ref:`PackedInt32Array<class_PackedInt32Array>` **triangulate_delaunay** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` points **)**
  289. Triangulates the area specified by discrete set of ``points`` such that no point is inside the circumcircle of any resulting triangle. Returns a :ref:`PackedInt32Array<class_PackedInt32Array>` where each triangle consists of three consecutive point indices into ``points`` (i.e. the returned array will have ``n * 3`` elements, with ``n`` being the number of found triangles). If the triangulation did not succeed, an empty :ref:`PackedInt32Array<class_PackedInt32Array>` is returned.
  290. .. rst-class:: classref-item-separator
  291. ----
  292. .. _class_Geometry2D_method_triangulate_polygon:
  293. .. rst-class:: classref-method
  294. :ref:`PackedInt32Array<class_PackedInt32Array>` **triangulate_polygon** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` polygon **)**
  295. Triangulates the polygon specified by the points in ``polygon``. Returns a :ref:`PackedInt32Array<class_PackedInt32Array>` where each triangle consists of three consecutive point indices into ``polygon`` (i.e. the returned array will have ``n * 3`` elements, with ``n`` being the number of found triangles). Output triangles will always be counter clockwise, and the contour will be flipped if it's clockwise. If the triangulation did not succeed, an empty :ref:`PackedInt32Array<class_PackedInt32Array>` is returned.
  296. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  297. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  298. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  299. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  300. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  301. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  302. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`