1. Vernon Cole
  2. ZipCodes.py

Commits

Vernon Cole  committed 253646e

Don't crash when finding distance between a point and itself.

  • Participants
  • Parent commits 66cabfe
  • Branches default

Comments (0)

Files changed (2)

File README.txt

View file
  python module which can access it and calculate distances based on it.
 
  This is version 0.0 then.
+   -- version 0.1:   fix bug for zero distance (same point)
 
  Copyright 2013 Vernon D. Cole
 

File arc_distance.py

View file
         theta = long_2 - long_1
         a = math.sin(lat_1) * math.sin(lat_2) + \
             math.cos(lat_1) * math.cos(lat_2) * math.cos(theta)
-        c = math.acos(a) # angular distance
-        if c < 0:
-            c += math.pi # normalize
+        try:
+            c = math.acos(a)  # angular distance
+        except ValueError:
+            c = 0.0
+        if c < 0.0:
+            c += math.pi  # normalize
         return c
 
 def dist(p1,p2):