Skip to content

Commit

Permalink
Correct returns when no path could be found
Browse files Browse the repository at this point in the history
Methods that return an array when a path is found now return [] instead of None if no path can be found
  • Loading branch information
JustineFricou committed May 13, 2024
1 parent a09f744 commit 5e79931
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions geotrek/core/path_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_edge_weight(self, edge_id):
def get_route(self, steps):
self.steps = steps
line_strings = self.compute_list_of_paths()
if line_strings is None:
if line_strings == []:
return None

multi_line_string = GeometryCollection(line_strings, srid=settings.SRID)
Expand All @@ -166,8 +166,8 @@ def compute_list_of_paths(self):
from_step = self.steps[i]
to_step = self.steps[i + 1]
line_strings = self.compute_two_steps_line_strings(from_step, to_step)
if line_strings is None:
return None
if line_strings == []:
return []
merged_line_string = self.merge_line_strings(line_strings)
all_line_strings.append(merged_line_string)
return all_line_strings
Expand All @@ -178,8 +178,8 @@ def compute_two_steps_line_strings(self, from_step, to_step):

shortest_path = self.get_shortest_path(from_node_info['node_id'],
to_node_info['node_id'])
if shortest_path is None:
return None
if shortest_path == []:
return []
line_strings = self.node_list_to_line_strings(shortest_path,
from_node_info, to_node_info)

Expand Down Expand Up @@ -417,7 +417,7 @@ def get_node_id_per_idx(node_idx):
while current_node_id != from_node_id:
if current_node_idx < 0:
# The path ends here but this node is not the destination
return None
return []
current_node_idx = predecessors[current_node_idx]
current_node_id = get_node_id_per_idx(current_node_idx)
path.append(current_node_id)
Expand Down

0 comments on commit 5e79931

Please sign in to comment.