Last active
December 16, 2015 07:09
-
-
Save DeaconDesperado/5396884 to your computer and use it in GitHub Desktop.
A modulus-based 2D coordinate normalizer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) |
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
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.