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
41typedef uint64_t GeoHashFix52Bits;
42typedef uint64_t GeoHashVarBits;
43
44typedef struct {
45 GeoHashBits hash;
46 GeoHashArea area;
47 GeoHashNeighbors neighbors;
48} GeoHashRadius;
49
50uint8_t geohashEstimateStepsByRadius(double range_meters, double lat);
51int geohashBoundingBox(GeoShape *shape, double *bounds);
52GeoHashRadius geohashCalculateAreasByShapeWGS84(GeoShape *shape);
53GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits hash);
54double geohashGetDistance(double lon1d, double lat1d,
55 double lon2d, double lat2d);
56int geohashGetDistanceIfInRadius(double x1, double y1,
57 double x2, double y2, double radius,
58 double *distance);
59int geohashGetDistanceIfInRadiusWGS84(double x1, double y1, double x2,
60 double y2, double radius,
61 double *distance);
62int geohashGetDistanceIfInRectangle(double width_m, double height_m, double x1, double y1,
63 double x2, double y2, double *distance);
64
65#endif /* GEOHASH_HELPER_HPP_ */
66