1 /* 2 * Copyright (c) 2013-2014, yinqiwen <[email protected]> 3 * Copyright (c) 2014, Matt Stancliff <[email protected]>. 4 * Copyright (c) 2015, Salvatore Sanfilippo <[email protected]>. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 9 * 10 * * Redistributions of source code must retain the above copyright notice, 11 * this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * * Neither the name of Redis nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without 17 * specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 * THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef GEOHASH_HELPER_HPP_ 33 #define GEOHASH_HELPER_HPP_ 34 35 #include "geohash.h" 36 37 #define GZERO(s) s.bits = s.step = 0; 38 #define GISZERO(s) (!s.bits && !s.step) 39 #define GISNOTZERO(s) (s.bits || s.step) 40 41 typedef uint64_t GeoHashFix52Bits; 42 typedef uint64_t GeoHashVarBits; 43 44 typedef struct { 45 GeoHashBits hash; 46 GeoHashArea area; 47 GeoHashNeighbors neighbors; 48 } GeoHashRadius; 49 50 int GeoHashBitsComparator(const GeoHashBits *a, const GeoHashBits *b); 51 uint8_t geohashEstimateStepsByRadius(double range_meters, double lat); 52 int geohashBoundingBox(double longitude, double latitude, double radius_meters, 53 double *bounds); 54 GeoHashRadius geohashGetAreasByRadius(double longitude, 55 double latitude, double radius_meters); 56 GeoHashRadius geohashGetAreasByRadiusWGS84(double longitude, double latitude, 57 double radius_meters); 58 GeoHashRadius geohashGetAreasByRadiusMercator(double longitude, double latitude, 59 double radius_meters); 60 GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits hash); 61 double geohashGetDistance(double lon1d, double lat1d, 62 double lon2d, double lat2d); 63 int geohashGetDistanceIfInRadius(double x1, double y1, 64 double x2, double y2, double radius, 65 double *distance); 66 int geohashGetDistanceIfInRadiusWGS84(double x1, double y1, double x2, 67 double y2, double radius, 68 double *distance); 69 70 #endif /* GEOHASH_HELPER_HPP_ */ 71