perf(nav): compute legs lazily

No need to build a whole list every time.
This commit is contained in:
Dr. Honk 2026-09-29 23:51:00 +02:00
commit 0ec9ac0388

5
nav.py
View file

@ -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):