summaryrefslogtreecommitdiff
path: root/deps
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-07-06 16:02:38 +0200
committerantirez <antirez@gmail.com>2016-07-06 16:02:38 +0200
commiteaa713e93b6aadf08fda33238670cd3577a7db52 (patch)
treed08c1ab5df92bfc29c93428453ad9f583da2715a /deps
parent4a140d320f7a8e1a63f9c3ca588f61f21838f3ac (diff)
downloadredis-eaa713e93b6aadf08fda33238670cd3577a7db52.tar.gz
geohash.c and geohash_helper.c are part of Redis.
They were under /deps since they originate from a different source tree, however at this point they are very modified and we took ownership of both the files making changes, fixing bugs, so there is no upgrade path from the original code tree. Given that, better to move the code under /src with proper dependencies and with a more simpler editing experience.
Diffstat (limited to 'deps')
-rw-r--r--deps/Makefile7
-rw-r--r--deps/geohash-int/Makefile23
-rw-r--r--deps/geohash-int/geohash.c295
-rw-r--r--deps/geohash-int/geohash.h118
-rw-r--r--deps/geohash-int/geohash_helper.c197
-rw-r--r--deps/geohash-int/geohash_helper.h71
6 files changed, 0 insertions, 711 deletions
diff --git a/deps/Makefile b/deps/Makefile
index 1c10bce9e..e148a331c 100644
--- a/deps/Makefile
+++ b/deps/Makefile
@@ -36,7 +36,6 @@ distclean:
-(cd hiredis && $(MAKE) clean) > /dev/null || true
-(cd linenoise && $(MAKE) clean) > /dev/null || true
-(cd lua && $(MAKE) clean) > /dev/null || true
- -(cd geohash-int && $(MAKE) clean) > /dev/null || true
-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
-(rm -f .make-*)
@@ -82,9 +81,3 @@ jemalloc: .make-prerequisites
cd jemalloc && $(MAKE) CFLAGS="$(JEMALLOC_CFLAGS)" LDFLAGS="$(JEMALLOC_LDFLAGS)" lib/libjemalloc.a
.PHONY: jemalloc
-
-geohash-int: .make-prerequisites
- @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
- cd geohash-int && $(MAKE)
-
-.PHONY: geohash-int
diff --git a/deps/geohash-int/Makefile b/deps/geohash-int/Makefile
deleted file mode 100644
index b7c259577..000000000
--- a/deps/geohash-int/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-STD=
-WARN= -Wall
-OPT= -O2
-
-R_CFLAGS= $(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS)
-R_LDFLAGS= $(LDFLAGS)
-DEBUG= -g
-
-R_CC=$(CC) $(R_CFLAGS)
-R_LD=$(CC) $(R_LDFLAGS)
-
-all: geohash.o geohash_helper.o
-
-.PHONY: all
-
-geohash.o: geohash.h geohash.c
-geohash_helper.o: geohash.h geohash_helper.h geohash_helper.c
-
-.c.o:
- $(R_CC) -c $<
-
-clean:
- rm -f *.o
diff --git a/deps/geohash-int/geohash.c b/deps/geohash-int/geohash.c
deleted file mode 100644
index d3bc7de25..000000000
--- a/deps/geohash-int/geohash.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Copyright (c) 2013-2014, yinqiwen <yinqiwen@gmail.com>
- * Copyright (c) 2014, Matt Stancliff <matt@genges.com>.
- * Copyright (c) 2015, Salvatore Sanfilippo <antirez@gmail.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Redis nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "geohash.h"
-
-/**
- * Hashing works like this:
- * Divide the world into 4 buckets. Label each one as such:
- * -----------------
- * | | |
- * | | |
- * | 0,1 | 1,1 |
- * -----------------
- * | | |
- * | | |
- * | 0,0 | 1,0 |
- * -----------------
- */
-
-/* Interleave lower bits of x and y, so the bits of x
- * are in the even positions and bits from y in the odd;
- * x and y must initially be less than 2**32 (65536).
- * From: https://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
- */
-static inline uint64_t interleave64(uint32_t xlo, uint32_t ylo) {
- static const uint64_t B[] = {0x5555555555555555ULL, 0x3333333333333333ULL,
- 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
- 0x0000FFFF0000FFFFULL};
- static const unsigned int S[] = {1, 2, 4, 8, 16};
-
- uint64_t x = xlo;
- uint64_t y = ylo;
-
- x = (x | (x << S[4])) & B[4];
- y = (y | (y << S[4])) & B[4];
-
- x = (x | (x << S[3])) & B[3];
- y = (y | (y << S[3])) & B[3];
-
- x = (x | (x << S[2])) & B[2];
- y = (y | (y << S[2])) & B[2];
-
- x = (x | (x << S[1])) & B[1];
- y = (y | (y << S[1])) & B[1];
-
- x = (x | (x << S[0])) & B[0];
- y = (y | (y << S[0])) & B[0];
-
- return x | (y << 1);
-}
-
-/* reverse the interleave process
- * derived from http://stackoverflow.com/questions/4909263
- */
-static inline uint64_t deinterleave64(uint64_t interleaved) {
- static const uint64_t B[] = {0x5555555555555555ULL, 0x3333333333333333ULL,
- 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
- 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL};
- static const unsigned int S[] = {0, 1, 2, 4, 8, 16};
-
- uint64_t x = interleaved;
- uint64_t y = interleaved >> 1;
-
- x = (x | (x >> S[0])) & B[0];
- y = (y | (y >> S[0])) & B[0];
-
- x = (x | (x >> S[1])) & B[1];
- y = (y | (y >> S[1])) & B[1];
-
- x = (x | (x >> S[2])) & B[2];
- y = (y | (y >> S[2])) & B[2];
-
- x = (x | (x >> S[3])) & B[3];
- y = (y | (y >> S[3])) & B[3];
-
- x = (x | (x >> S[4])) & B[4];
- y = (y | (y >> S[4])) & B[4];
-
- x = (x | (x >> S[5])) & B[5];
- y = (y | (y >> S[5])) & B[5];
-
- return x | (y << 32);
-}
-
-void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range) {
- /* These are constraints from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
- /* We can't geocode at the north/south pole. */
- long_range->max = GEO_LONG_MAX;
- long_range->min = GEO_LONG_MIN;
- lat_range->max = GEO_LAT_MAX;
- lat_range->min = GEO_LAT_MIN;
-}
-
-int geohashEncode(GeoHashRange *long_range, GeoHashRange *lat_range,
- double longitude, double latitude, uint8_t step,
- GeoHashBits *hash) {
- /* Check basic arguments sanity. */
- if (hash == NULL || step > 32 || step == 0 ||
- RANGEPISZERO(lat_range) || RANGEPISZERO(long_range)) return 0;
-
- /* Return an error when trying to index outside the supported
- * constraints. */
- if (longitude > 180 || longitude < -180 ||
- latitude > 85.05112878 || latitude < -85.05112878) return 0;
-
- hash->bits = 0;
- hash->step = step;
-
- if (latitude < lat_range->min || latitude > lat_range->max ||
- longitude < long_range->min || longitude > long_range->max) {
- return 0;
- }
-
- double lat_offset =
- (latitude - lat_range->min) / (lat_range->max - lat_range->min);
- double long_offset =
- (longitude - long_range->min) / (long_range->max - long_range->min);
-
- /* convert to fixed point based on the step size */
- lat_offset *= (1 << step);
- long_offset *= (1 << step);
- hash->bits = interleave64(lat_offset, long_offset);
- return 1;
-}
-
-int geohashEncodeType(double longitude, double latitude, uint8_t step, GeoHashBits *hash) {
- GeoHashRange r[2] = { { 0 } };
- geohashGetCoordRange(&r[0], &r[1]);
- return geohashEncode(&r[0], &r[1], longitude, latitude, step, hash);
-}
-
-int geohashEncodeWGS84(double longitude, double latitude, uint8_t step,
- GeoHashBits *hash) {
- return geohashEncodeType(longitude, latitude, step, hash);
-}
-
-int geohashDecode(const GeoHashRange long_range, const GeoHashRange lat_range,
- const GeoHashBits hash, GeoHashArea *area) {
- if (HASHISZERO(hash) || NULL == area || RANGEISZERO(lat_range) ||
- RANGEISZERO(long_range)) {
- return 0;
- }
-
- area->hash = hash;
- uint8_t step = hash.step;
- uint64_t hash_sep = deinterleave64(hash.bits); /* hash = [LAT][LONG] */
-
- double lat_scale = lat_range.max - lat_range.min;
- double long_scale = long_range.max - long_range.min;
-
- uint32_t ilato = hash_sep; /* get lat part of deinterleaved hash */
- uint32_t ilono = hash_sep >> 32; /* shift over to get long part of hash */
-
- /* divide by 2**step.
- * Then, for 0-1 coordinate, multiply times scale and add
- to the min to get the absolute coordinate. */
- area->latitude.min =
- lat_range.min + (ilato * 1.0 / (1ull << step)) * lat_scale;
- area->latitude.max =
- lat_range.min + ((ilato + 1) * 1.0 / (1ull << step)) * lat_scale;
- area->longitude.min =
- long_range.min + (ilono * 1.0 / (1ull << step)) * long_scale;
- area->longitude.max =
- long_range.min + ((ilono + 1) * 1.0 / (1ull << step)) * long_scale;
-
- return 1;
-}
-
-int geohashDecodeType(const GeoHashBits hash, GeoHashArea *area) {
- GeoHashRange r[2] = { { 0 } };
- geohashGetCoordRange(&r[0], &r[1]);
- return geohashDecode(r[0], r[1], hash, area);
-}
-
-int geohashDecodeWGS84(const GeoHashBits hash, GeoHashArea *area) {
- return geohashDecodeType(hash, area);
-}
-
-int geohashDecodeAreaToLongLat(const GeoHashArea *area, double *xy) {
- if (!xy) return 0;
- xy[0] = (area->longitude.min + area->longitude.max) / 2;
- xy[1] = (area->latitude.min + area->latitude.max) / 2;
- return 1;
-}
-
-int geohashDecodeToLongLatType(const GeoHashBits hash, double *xy) {
- GeoHashArea area = { { 0 } };
- if (!xy || !geohashDecodeType(hash, &area))
- return 0;
- return geohashDecodeAreaToLongLat(&area, xy);
-}
-
-int geohashDecodeToLongLatWGS84(const GeoHashBits hash, double *xy) {
- return geohashDecodeToLongLatType(hash, xy);
-}
-
-static void geohash_move_x(GeoHashBits *hash, int8_t d) {
- if (d == 0)
- return;
-
- uint64_t x = hash->bits & 0xaaaaaaaaaaaaaaaaULL;
- uint64_t y = hash->bits & 0x5555555555555555ULL;
-
- uint64_t zz = 0x5555555555555555ULL >> (64 - hash->step * 2);
-
- if (d > 0) {
- x = x + (zz + 1);
- } else {
- x = x | zz;
- x = x - (zz + 1);
- }
-
- x &= (0xaaaaaaaaaaaaaaaaULL >> (64 - hash->step * 2));
- hash->bits = (x | y);
-}
-
-static void geohash_move_y(GeoHashBits *hash, int8_t d) {
- if (d == 0)
- return;
-
- uint64_t x = hash->bits & 0xaaaaaaaaaaaaaaaaULL;
- uint64_t y = hash->bits & 0x5555555555555555ULL;
-
- uint64_t zz = 0xaaaaaaaaaaaaaaaaULL >> (64 - hash->step * 2);
- if (d > 0) {
- y = y + (zz + 1);
- } else {
- y = y | zz;
- y = y - (zz + 1);
- }
- y &= (0x5555555555555555ULL >> (64 - hash->step * 2));
- hash->bits = (x | y);
-}
-
-void geohashNeighbors(const GeoHashBits *hash, GeoHashNeighbors *neighbors) {
- neighbors->east = *hash;
- neighbors->west = *hash;
- neighbors->north = *hash;
- neighbors->south = *hash;
- neighbors->south_east = *hash;
- neighbors->south_west = *hash;
- neighbors->north_east = *hash;
- neighbors->north_west = *hash;
-
- geohash_move_x(&neighbors->east, 1);
- geohash_move_y(&neighbors->east, 0);
-
- geohash_move_x(&neighbors->west, -1);
- geohash_move_y(&neighbors->west, 0);
-
- geohash_move_x(&neighbors->south, 0);
- geohash_move_y(&neighbors->south, -1);
-
- geohash_move_x(&neighbors->north, 0);
- geohash_move_y(&neighbors->north, 1);
-
- geohash_move_x(&neighbors->north_west, -1);
- geohash_move_y(&neighbors->north_west, 1);
-
- geohash_move_x(&neighbors->north_east, 1);
- geohash_move_y(&neighbors->north_east, 1);
-
- geohash_move_x(&neighbors->south_east, 1);
- geohash_move_y(&neighbors->south_east, -1);
-
- geohash_move_x(&neighbors->south_west, -1);
- geohash_move_y(&neighbors->south_west, -1);
-}
diff --git a/deps/geohash-int/geohash.h b/deps/geohash-int/geohash.h
deleted file mode 100644
index c2f57bed0..000000000
--- a/deps/geohash-int/geohash.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 2013-2014, yinqiwen <yinqiwen@gmail.com>
- * Copyright (c) 2014, Matt Stancliff <matt@genges.com>.
- * Copyright (c) 2015, Salvatore Sanfilippo <antirez@gmail.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Redis nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GEOHASH_H_
-#define GEOHASH_H_
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdint.h>
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#define HASHISZERO(r) (!(r).bits && !(r).step)
-#define RANGEISZERO(r) (!(r).max && !(r).min)
-#define RANGEPISZERO(r) (r == NULL || RANGEISZERO(*r))
-
-#define GEO_STEP_MAX 26 /* 26*2 = 52 bits. */
-
-/* Limits from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
-#define GEO_LAT_MIN -85.05112878
-#define GEO_LAT_MAX 85.05112878
-#define GEO_LONG_MIN -180
-#define GEO_LONG_MAX 180
-
-typedef enum {
- GEOHASH_NORTH = 0,
- GEOHASH_EAST,
- GEOHASH_WEST,
- GEOHASH_SOUTH,
- GEOHASH_SOUTH_WEST,
- GEOHASH_SOUTH_EAST,
- GEOHASH_NORT_WEST,
- GEOHASH_NORT_EAST
-} GeoDirection;
-
-typedef struct {
- uint64_t bits;
- uint8_t step;
-} GeoHashBits;
-
-typedef struct {
- double min;
- double max;
-} GeoHashRange;
-
-typedef struct {
- GeoHashBits hash;
- GeoHashRange longitude;
- GeoHashRange latitude;
-} GeoHashArea;
-
-typedef struct {
- GeoHashBits north;
- GeoHashBits east;
- GeoHashBits west;
- GeoHashBits south;
- GeoHashBits north_east;
- GeoHashBits south_east;
- GeoHashBits north_west;
- GeoHashBits south_west;
-} GeoHashNeighbors;
-
-/*
- * 0:success
- * -1:failed
- */
-void geohashGetCoordRange(GeoHashRange *long_range, GeoHashRange *lat_range);
-int geohashEncode(GeoHashRange *long_range, GeoHashRange *lat_range,
- double longitude, double latitude, uint8_t step,
- GeoHashBits *hash);
-int geohashEncodeType(double longitude, double latitude,
- uint8_t step, GeoHashBits *hash);
-int geohashEncodeWGS84(double longitude, double latitude, uint8_t step,
- GeoHashBits *hash);
-int geohashDecode(const GeoHashRange long_range, const GeoHashRange lat_range,
- const GeoHashBits hash, GeoHashArea *area);
-int geohashDecodeType(const GeoHashBits hash, GeoHashArea *area);
-int geohashDecodeWGS84(const GeoHashBits hash, GeoHashArea *area);
-int geohashDecodeAreaToLongLat(const GeoHashArea *area, double *xy);
-int geohashDecodeToLongLatType(const GeoHashBits hash, double *xy);
-int geohashDecodeToLongLatWGS84(const GeoHashBits hash, double *xy);
-int geohashDecodeToLongLatMercator(const GeoHashBits hash, double *xy);
-void geohashNeighbors(const GeoHashBits *hash, GeoHashNeighbors *neighbors);
-
-#if defined(__cplusplus)
-}
-#endif
-#endif /* GEOHASH_H_ */
diff --git a/deps/geohash-int/geohash_helper.c b/deps/geohash-int/geohash_helper.c
deleted file mode 100644
index 4b8894676..000000000
--- a/deps/geohash-int/geohash_helper.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright (c) 2013-2014, yinqiwen <yinqiwen@gmail.com>
- * Copyright (c) 2014, Matt Stancliff <matt@genges.com>.
- * Copyright (c) 2015, Salvatore Sanfilippo <antirez@gmail.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Redis nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/* This is a C++ to C conversion from the ardb project.
- * This file started out as:
- * https://github.com/yinqiwen/ardb/blob/d42503/src/geo/geohash_helper.cpp
- */
-
-#include "geohash_helper.h"
-
-#define D_R (M_PI / 180.0)
-#define R_MAJOR 6378137.0
-#define R_MINOR 6356752.3142
-#define RATIO (R_MINOR / R_MAJOR)
-#define ECCENT (sqrt(1.0 - (RATIO *RATIO)))
-#define COM (0.5 * ECCENT)
-
-/// @brief The usual PI/180 constant
-const double DEG_TO_RAD = 0.017453292519943295769236907684886;
-/// @brief Earth's quatratic mean radius for WGS-84
-const double EARTH_RADIUS_IN_METERS = 6372797.560856;
-
-const double MERCATOR_MAX = 20037726.37;
-const double MERCATOR_MIN = -20037726.37;
-
-static inline double deg_rad(double ang) { return ang * D_R; }
-static inline double rad_deg(double ang) { return ang / D_R; }
-
-/* You must *ONLY* estimate steps when you are encoding.
- * If you are decoding, always decode to GEO_STEP_MAX (26). */
-uint8_t geohashEstimateStepsByRadius(double range_meters, double lat) {
- if (range_meters == 0) return 26;
- int step = 1;
- while (range_meters < MERCATOR_MAX) {
- range_meters *= 2;
- step++;
- }
- step -= 2; /* Make sure range is included in the worst case. */
- /* Wider range torwards the poles... Note: it is possible to do better
- * than this approximation by computing the distance between meridians
- * at this latitude, but this does the trick for now. */
- if (lat > 67 || lat < -67) step--;
- if (lat > 80 || lat < -80) step--;
-
- /* Frame to valid range. */
- if (step < 1) step = 1;
- if (step > 26) step = 26;
- return step;
-}
-
-int geohashBitsComparator(const GeoHashBits *a, const GeoHashBits *b) {
- /* If step not equal, compare on step. Else, compare on bits. */
- return a->step != b->step ? a->step - b->step : a->bits - b->bits;
-}
-
-int geohashBoundingBox(double longitude, double latitude, double radius_meters,
- double *bounds) {
- if (!bounds) return 0;
-
- double lonr, latr;
- lonr = deg_rad(longitude);
- latr = deg_rad(latitude);
-
- if (radius_meters > EARTH_RADIUS_IN_METERS)
- radius_meters = EARTH_RADIUS_IN_METERS;
- double distance = radius_meters / EARTH_RADIUS_IN_METERS;
- double min_latitude = latr - distance;
- double max_latitude = latr + distance;
-
- /* Note: we're being lazy and not accounting for coordinates near poles */
- double min_longitude, max_longitude;
- double difference_longitude = asin(sin(distance) / cos(latr));
- min_longitude = lonr - difference_longitude;
- max_longitude = lonr + difference_longitude;
-
- bounds[0] = rad_deg(min_longitude);
- bounds[1] = rad_deg(min_latitude);
- bounds[2] = rad_deg(max_longitude);
- bounds[3] = rad_deg(max_latitude);
- return 1;
-}
-
-GeoHashRadius geohashGetAreasByRadius(double longitude, double latitude, double radius_meters) {
- GeoHashRange long_range, lat_range;
- GeoHashRadius radius = { { 0 } };
- GeoHashBits hash = { 0 };
- GeoHashNeighbors neighbors = { { 0 } };
- GeoHashArea area = { { 0 } };
- double min_lon, max_lon, min_lat, max_lat;
- double bounds[4];
- int steps;
-
- geohashBoundingBox(longitude, latitude, radius_meters, bounds);
- min_lon = bounds[0];
- min_lat = bounds[1];
- max_lon = bounds[2];
- max_lat = bounds[3];
-
- steps = geohashEstimateStepsByRadius(radius_meters,latitude);
-
- geohashGetCoordRange(&long_range, &lat_range);
- geohashEncode(&long_range, &lat_range, longitude, latitude, steps, &hash);
- geohashNeighbors(&hash, &neighbors);
- geohashGetCoordRange(&long_range, &lat_range);
- geohashDecode(long_range, lat_range, hash, &area);
-
- if (area.latitude.min < min_lat) {
- GZERO(neighbors.south);
- GZERO(neighbors.south_west);
- GZERO(neighbors.south_east);
- }
- if (area.latitude.max > max_lat) {
- GZERO(neighbors.north);
- GZERO(neighbors.north_east);
- GZERO(neighbors.north_west);
- }
- if (area.longitude.min < min_lon) {
- GZERO(neighbors.west);
- GZERO(neighbors.south_west);
- GZERO(neighbors.north_west);
- }
- if (area.longitude.max > max_lon) {
- GZERO(neighbors.east);
- GZERO(neighbors.south_east);
- GZERO(neighbors.north_east);
- }
- radius.hash = hash;
- radius.neighbors = neighbors;
- radius.area = area;
- return radius;
-}
-
-GeoHashRadius geohashGetAreasByRadiusWGS84(double longitude, double latitude,
- double radius_meters) {
- return geohashGetAreasByRadius(longitude, latitude, radius_meters);
-}
-
-GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits hash) {
- uint64_t bits = hash.bits;
- bits <<= (52 - hash.step * 2);
- return bits;
-}
-
-/* Calculate distance using haversin great circle distance formula. */
-double geohashGetDistance(double lon1d, double lat1d, double lon2d, double lat2d) {
- double lat1r, lon1r, lat2r, lon2r, u, v;
- lat1r = deg_rad(lat1d);
- lon1r = deg_rad(lon1d);
- lat2r = deg_rad(lat2d);
- lon2r = deg_rad(lon2d);
- u = sin((lat2r - lat1r) / 2);
- v = sin((lon2r - lon1r) / 2);
- return 2.0 * EARTH_RADIUS_IN_METERS *
- asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v));
-}
-
-int geohashGetDistanceIfInRadius(double x1, double y1,
- double x2, double y2, double radius,
- double *distance) {
- *distance = geohashGetDistance(x1, y1, x2, y2);
- if (*distance > radius) return 0;
- return 1;
-}
-
-int geohashGetDistanceIfInRadiusWGS84(double x1, double y1, double x2,
- double y2, double radius,
- double *distance) {
- return geohashGetDistanceIfInRadius(x1, y1, x2, y2, radius, distance);
-}
diff --git a/deps/geohash-int/geohash_helper.h b/deps/geohash-int/geohash_helper.h
deleted file mode 100644
index bff111dbe..000000000
--- a/deps/geohash-int/geohash_helper.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2013-2014, yinqiwen <yinqiwen@gmail.com>
- * Copyright (c) 2014, Matt Stancliff <matt@genges.com>.
- * Copyright (c) 2015, Salvatore Sanfilippo <antirez@gmail.com>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Redis nor the names of its contributors may be used
- * to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GEOHASH_HELPER_HPP_
-#define GEOHASH_HELPER_HPP_
-
-#include <math.h>
-#include "geohash.h"
-
-#define GZERO(s) s.bits = s.step = 0;
-#define GISZERO(s) (!s.bits && !s.step)
-#define GISNOTZERO(s) (s.bits || s.step)
-
-typedef uint64_t GeoHashFix52Bits;
-typedef uint64_t GeoHashVarBits;
-
-typedef struct {
- GeoHashBits hash;
- GeoHashArea area;
- GeoHashNeighbors neighbors;
-} GeoHashRadius;
-
-int GeoHashBitsComparator(const GeoHashBits *a, const GeoHashBits *b);
-uint8_t geohashEstimateStepsByRadius(double range_meters, double lat);
-int geohashBoundingBox(double longitude, double latitude, double radius_meters,
- double *bounds);
-GeoHashRadius geohashGetAreasByRadius(double longitude,
- double latitude, double radius_meters);
-GeoHashRadius geohashGetAreasByRadiusWGS84(double longitude, double latitude,
- double radius_meters);
-GeoHashRadius geohashGetAreasByRadiusMercator(double longitude, double latitude,
- double radius_meters);
-GeoHashFix52Bits geohashAlign52Bits(const GeoHashBits hash);
-double geohashGetDistance(double lon1d, double lat1d,
- double lon2d, double lat2d);
-int geohashGetDistanceIfInRadius(double x1, double y1,
- double x2, double y2, double radius,
- double *distance);
-int geohashGetDistanceIfInRadiusWGS84(double x1, double y1, double x2,
- double y2, double radius,
- double *distance);
-
-#endif /* GEOHASH_HELPER_HPP_ */