Skip to content

Instantly share code, notes, and snippets.

@DeaconDesperado
Last active December 16, 2015 07:09
Show Gist options
  • Save DeaconDesperado/5396884 to your computer and use it in GitHub Desktop.
Save DeaconDesperado/5396884 to your computer and use it in GitHub Desktop.
A modulus-based 2D coordinate normalizer.
coords = (
(41.2863,-73.78689),
(41.2864,-73.78690),
(41.2869,-73.78698),
)
from math import floor
def gen_hash(coords):
pro_lat = floor(coords[0]*1000.0)
pro_lon = floor(coords[1]*1000.0)
mod_lat = pro_lat%4.0
mod_lon = pro_lon%4.0
return 'SERVER_NAME#%s|%s:%s|%s' % (pro_lat,mod_lat,pro_lon,mod_lon)
assert(gen_hash(coords[0])==gen_hash(coords[1]))
assert(gen_hash(coords[0])==gen_hash(coords[2]))
@myok12
Copy link

myok12 commented Apr 17, 2013

Since the key contains the entire pro_lat, concatenating prod_lat%4 achieves nothing:
pro_lat1==pro_lat2 ==> pro_lat1%4 == pro_lat2%4 (= iff... then...)

will revise it on my fork.

@DeaconDesperado
Copy link
Author

Thanks! I had thought the same thing after, I should remove the first digit of pro_lat and pro_lon, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment