diff options
| author | Gustav Sörnäs <gusso230@student.liu.se> | 2021-01-06 18:56:56 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gusso230@student.liu.se> | 2021-01-06 18:57:50 +0100 |
| commit | 62683f4cc52f2ff81719868e8f06b29af84d1269 (patch) | |
| tree | baabbad7eaf5c2794df4193dc70d5c3bf82930f7 | |
| parent | b52a7325c1e0d1b6e87e2bbe96ebafcc22be167a (diff) | |
| download | tdde25-62683f4cc52f2ff81719868e8f06b29af84d1269.tar.gz | |
comments
| -rw-r--r-- | algorithms.py | 12 |
1 files 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 |
