Skip to content

Commit 6125452

Browse files
committed
force math.floor to int to allow for compatibility with Python2 (where math.floor returns a float, which can't be used to index into a list) and make CodeArea class declaration more explicit.
1 parent 750a440 commit 6125452

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

python/openlocationcode.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def shorten(code,latitude,longitude):
364364
latitude: A latitude in signed decimal degrees.
365365
"""
366366
def clipLatitude(latitude):
367-
return min(90,max(-90,latitude))
367+
return min(90, max(-90, latitude))
368368

369369
"""
370370
Compute the latitude precision value for a given code length. Lengths <=
@@ -374,7 +374,7 @@ def clipLatitude(latitude):
374374
"""
375375
def computeLatitutePrecision(codeLength):
376376
if codeLength <= 10:
377-
return pow(20,math.floor((codeLength / -2) + 2))
377+
return pow(20, math.floor((codeLength / -2) + 2))
378378
return pow(20, -3) / pow(GRID_ROWS_, codeLength - 10)
379379

380380
"""
@@ -410,16 +410,16 @@ def encodePairs(latitude, longitude, codeLength):
410410
digitCount = 0
411411
while digitCount < codeLength:
412412
# Provides the value of digits in this place in decimal degrees.
413-
placeValue = PAIR_RESOLUTIONS_[math.floor(digitCount / 2)]
413+
placeValue = PAIR_RESOLUTIONS_[int(math.floor(digitCount / 2))]
414414
# Do the latitude - gets the digit for this place and subtracts that for
415415
# the next digit.
416-
digitValue = math.floor(adjustedLatitude / placeValue)
416+
digitValue = int(math.floor(adjustedLatitude / placeValue))
417417
adjustedLatitude -= digitValue * placeValue
418418
code += CODE_ALPHABET_[digitValue]
419419
digitCount += 1
420420
# And do the longitude - gets the digit for this place and subtracts that
421421
# for the next digit.
422-
digitValue = math.floor(adjustedLongitude / placeValue)
422+
digitValue = int(math.floor(adjustedLongitude / placeValue))
423423
adjustedLongitude -= digitValue * placeValue
424424
code += CODE_ALPHABET_[digitValue]
425425
digitCount += 1
@@ -452,8 +452,8 @@ def encodeGrid(latitude, longitude, codeLength):
452452
adjustedLongitude = (longitude + LONGITUDE_MAX_) % lngPlaceValue
453453
for i in range(codeLength):
454454
# Work out the row and column.
455-
row = math.floor(adjustedLatitude / (latPlaceValue / GRID_ROWS_))
456-
col = math.floor(adjustedLongitude / (lngPlaceValue / GRID_COLUMNS_))
455+
row = int(math.floor(adjustedLatitude / (latPlaceValue / GRID_ROWS_)))
456+
col = int(math.floor(adjustedLongitude / (lngPlaceValue / GRID_COLUMNS_)))
457457
latPlaceValue /= GRID_ROWS_
458458
lngPlaceValue /= GRID_COLUMNS_
459459
adjustedLatitude -= row * latPlaceValue
@@ -543,7 +543,7 @@ def decodeGrid(code):
543543
code_length: The number of significant characters that were in the code.
544544
This excludes the separator.
545545
"""
546-
class CodeArea:
546+
class CodeArea(object):
547547
def __init__(self,latitudeLo, longitudeLo, latitudeHi, longitudeHi, codeLength):
548548
self.latitudeLo = latitudeLo
549549
self.longitudeLo = longitudeLo

0 commit comments

Comments
 (0)