Expose Geometry2D.bresenham_line() method

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
Danil Alexeev
2024-10-21 08:19:00 +03:00
parent 78a4e634f0
commit 9f0ae21095
5 changed files with 38 additions and 7 deletions

View File

@@ -9,6 +9,20 @@
<tutorials>
</tutorials>
<methods>
<method name="bresenham_line">
<return type="Vector2i[]" />
<param index="0" name="from" type="Vector2i" />
<param index="1" name="to" type="Vector2i" />
<description>
Returns the [url=https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm]Bresenham line[/url] between the [param from] and [param to] points. A Bresenham line is a series of pixels that draws a line and is always 1-pixel thick on every row and column of the drawing (never more, never less).
Example code to draw a line between two [Marker2D] nodes using a series of [method CanvasItem.draw_rect] calls:
[codeblock]
func _draw():
for pixel in Geometry2D.bresenham_line($MarkerA.position, $MarkerB.position):
draw_rect(Rect2(pixel, Vector2.ONE), Color.WHITE)
[/codeblock]
</description>
</method>
<method name="clip_polygons">
<return type="PackedVector2Array[]" />
<param index="0" name="polygon_a" type="PackedVector2Array" />