Currently, AStarPathPlanning.get_distance() returns 0.0 when no path exists between two entities.
When the destination is unreachable, get_path() returns an empty list:
However, get_distance() initializes the distance to 0.0 and sums the distances along the returned path:
path: list[EntityID] = self.get_path(from_entity_id, to_entity_id)
distance: float = 0.0
for i in range(len(path) - 1):
distance += self.distance(path[i], path[i + 1])
return distance
As a result, get_distance() returns 0.0 when get_path() returns an empty list.
This makes an unreachable destination indistinguishable from being at the destination itself (a true zero-distance case). It can also cause issues such as selecting an unreachable target as the nearest one when selecting targets based on path distance.
Would it be better for get_distance() to return float("inf") when no path exists?
Alternatively, if returning 0.0 for unreachable destinations is intentional, should this behavior be explicitly documented?
Currently,
AStarPathPlanning.get_distance()returns0.0when no path exists between two entities.When the destination is unreachable,
get_path()returns an empty list:return []However,
get_distance()initializes the distance to0.0and sums the distances along the returned path:As a result,
get_distance()returns0.0whenget_path()returns an empty list.This makes an unreachable destination indistinguishable from being at the destination itself (a true zero-distance case). It can also cause issues such as selecting an unreachable target as the nearest one when selecting targets based on path distance.
Would it be better for
get_distance()to returnfloat("inf")when no path exists?Alternatively, if returning
0.0for unreachable destinations is intentional, should this behavior be explicitly documented?