From 62683f4cc52f2ff81719868e8f06b29af84d1269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 6 Jan 2021 18:56:56 +0100 Subject: comments --- algorithms.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/algorithms.py b/algorithms.py index e2da8f0..5423398 100644 --- a/algorithms.py +++ b/algorithms.py @@ -3,6 +3,11 @@ import math def length_haversine(p1, p2): + """ + The distance in meters between two coordinates on a sphere. + + Assumes p1=(lat1, lng1) and p2=(lat2, lng2) in degrees. + """ lat1 = p1.lat lng1 = p1.lng lat2 = p2.lat @@ -42,6 +47,7 @@ def find_nodes(offset, grid, source_key): """ tiles = None + # search further out until we find nodes while not tiles: tiles = look_for_nodes(offset, grid, source_key) offset += 1 @@ -50,7 +56,7 @@ def find_nodes(offset, grid, source_key): def look_for_nodes(offset, grid, source_key): - """Search for nearest tile containing nodes in an outward spiral.""" + """Search for nearest tile containing nodes in a spiral.""" tiles = [] for i in range(-offset, offset + 1): for j in range(-offset, offset + 1): @@ -63,8 +69,8 @@ def look_for_nodes(offset, grid, source_key): def get_closest_node(nodes, source_node): """ - Searches through all nodes in a specified grid and return node - closes to source node. + Search through all nodes in a specified grid and return the node + closest to source_node. """ min_node = None min_value = None -- cgit v1.2.1