Improve documentation on heuristics in AStarGrid2D

This commit is contained in:
Yuri Rubinsky 2022-12-14 16:35:02 +03:00
parent ec4de82ab3
commit ecd2c5d5b9

View File

@ -103,6 +103,7 @@
<param index="1" name="solid" type="bool" default="true" /> <param index="1" name="solid" type="bool" default="true" />
<description> <description>
Disables or enables the specified point for pathfinding. Useful for making an obstacle. By default, all points are enabled. Disables or enables the specified point for pathfinding. Useful for making an obstacle. By default, all points are enabled.
[b]Note:[/b] Calling [method update] is not needed after the call of this function.
</description> </description>
</method> </method>
<method name="update"> <method name="update">
@ -134,20 +135,22 @@
</members> </members>
<constants> <constants>
<constant name="HEURISTIC_EUCLIDEAN" value="0" enum="Heuristic"> <constant name="HEURISTIC_EUCLIDEAN" value="0" enum="Heuristic">
The Euclidean heuristic to be used for the pathfinding using the following formula: The [url=https://en.wikipedia.org/wiki/Euclidean_distance]Euclidean heuristic[/url] to be used for the pathfinding using the following formula:
[codeblock] [codeblock]
dx = abs(to_id.x - from_id.x) dx = abs(to_id.x - from_id.x)
dy = abs(to_id.y - from_id.y) dy = abs(to_id.y - from_id.y)
result = sqrt(dx * dx + dy * dy) result = sqrt(dx * dx + dy * dy)
[/codeblock] [/codeblock]
[b]Note:[/b] This is also the internal heuristic used in [AStar3D] and [AStar2D] by default (with the inclusion of possible z-axis coordinate).
</constant> </constant>
<constant name="HEURISTIC_MANHATTAN" value="1" enum="Heuristic"> <constant name="HEURISTIC_MANHATTAN" value="1" enum="Heuristic">
The Manhattan heuristic to be used for the pathfinding using the following formula: The [url=https://en.wikipedia.org/wiki/Taxicab_geometry]Manhattan heuristic[/url] to be used for the pathfinding using the following formula:
[codeblock] [codeblock]
dx = abs(to_id.x - from_id.x) dx = abs(to_id.x - from_id.x)
dy = abs(to_id.y - from_id.y) dy = abs(to_id.y - from_id.y)
result = dx + dy result = dx + dy
[/codeblock] [/codeblock]
[b]Note:[/b] This heuristic is intended to be used with 4-side orthogonal movements, provided by setting the [member diagonal_mode] to [constant DIAGONAL_MODE_NEVER].
</constant> </constant>
<constant name="HEURISTIC_OCTILE" value="2" enum="Heuristic"> <constant name="HEURISTIC_OCTILE" value="2" enum="Heuristic">
The Octile heuristic to be used for the pathfinding using the following formula: The Octile heuristic to be used for the pathfinding using the following formula:
@ -159,7 +162,7 @@
[/codeblock] [/codeblock]
</constant> </constant>
<constant name="HEURISTIC_CHEBYSHEV" value="3" enum="Heuristic"> <constant name="HEURISTIC_CHEBYSHEV" value="3" enum="Heuristic">
The Chebyshev heuristic to be used for the pathfinding using the following formula: The [url=https://en.wikipedia.org/wiki/Chebyshev_distance]Chebyshev heuristic[/url] to be used for the pathfinding using the following formula:
[codeblock] [codeblock]
dx = abs(to_id.x - from_id.x) dx = abs(to_id.x - from_id.x)
dy = abs(to_id.y - from_id.y) dy = abs(to_id.y - from_id.y)