Permalink
Browse files

Fix a bug in edge interpolation caused by zero-length segments.

  • Loading branch information...
1 parent 694e94a commit e8ada9b71b916e7f891f2b3b0d82d51fe61ad1f3 Schuyler Erle committed Jun 16, 2011
Showing with 5 additions and 2 deletions.
  1. +1 −1 demos/cli.rb
  2. +4 −1 lib/geocoder/us/database.rb
View
@@ -1,7 +1,7 @@
require 'geocoder/us/database'
require 'pp'
-db = Geocoder::US::Database.new("/mnt/geocoder-us/geocoder.db", :debug=>true)
+db = Geocoder::US::Database.new("/mnt/tiger2010/geocoder.db", :debug=>true)
result = db.geocode(ARGV[0])
pp(result)
print "#{result[0][:lat]} N, #{-result[0][:lon]} W\n"
@@ -571,6 +571,7 @@ def interpolate (points, fraction, side, offset=0.000075)
(1...points.length).each {|n| total += distance(points[n-1], points[n])}
target = total * fraction
for n in 1...points.length
+ next if points[n-1] == points[n] # because otherwise step==0 and dx/dy==NaN
step = distance(points[n-1], points[n])
if step < target
target -= step
@@ -582,7 +583,9 @@ def interpolate (points, fraction, side, offset=0.000075)
return street_side_offset(offset*side, points[n-1], found)
end
end
- # raise "Can't happen!"
+ # in a pathological case, points[n-1] == points[n] for n==-1
+ # so *sigh* just forget interpolating and return points[-1]
+ return points[-1]
end
# Find and replace the city, state, and county information

0 comments on commit e8ada9b

Please sign in to comment.