perf(nav): compute legs lazily
No need to build a whole list every time.
This commit is contained in:
parent
6bcd1dfca6
commit
0ec9ac0388
1 changed files with 3 additions and 2 deletions
5
nav.py
5
nav.py
|
|
@ -79,8 +79,9 @@ def distance(a, b):
|
|||
|
||||
|
||||
def legs(route):
|
||||
"""Return the legs (pairs of consecutive waypoints) of a route."""
|
||||
return [(route[i], route[i + 1]) for i in range(len(route) - 1)]
|
||||
"""Yield the legs (pairs of consecutive waypoints) of a route."""
|
||||
for i in range(1, len(route) - 1):
|
||||
yield route[i], route[i + 1]
|
||||
|
||||
|
||||
def plan(destination):
|
||||
|
|
|
|||
Loading…
Reference in a new issue