• antirez's avatar
    Geo: Fix geohashEstimateStepsByRadius() step underestimation. · 55c4a365
    antirez authored
    The returned step was in some case not enough towards normal
    coordinates (for example when our search position was was already near the
    margin of the central area, and we had to match, using the east or west
    neighbor, a very far point). Example:
    
        geoadd points 67.575457940146066 -62.001317572780565 far
        geoadd points 66.685439060295664 -58.925040587282297 center
        georadius points 66.685439060295664 -58.925040587282297 200 km
    
    In the above case the code failed to find a match (happens at smaller
    latitudes too) even if far and center are at less than 200km.
    
    Another fix introduced by this commit is a progressively larger area
    towards the poles, since meridians are a lot less far away, so we need
    to compensate for this.
    
    The current implementation works comparably to the Tcl brute-force
    stress tester implemented in the fuzzy test in the geo.tcl unit for
    latitudes between -70 and 70, and is pretty accurate over +/-80 too,
    with sporadic false negatives.
    
    A more mathematically clean implementation is possible by computing the
    meridian distance at the specified latitude and computing the step
    according to it.
    55c4a365
geohash_helper.c 7.41 KB