#include "liblwgeom_internal.h"
#include "lwgeom_log.h"
#include <ctype.h> /* for tolower */
+#include <stdbool.h>
int
p4d_same(const POINT4D *p1, const POINT4D *p2)
*/
void decode_geohash_bbox(char *geohash, double *lat, double *lon, int precision)
{
- int i, j, hashlen;
- char c, cd, mask, is_even = 1;
- static char bits[] = {16, 8, 4, 2, 1};
+ bool is_even = 1;
lat[0] = -90.0;
lat[1] = 90.0;
lon[0] = -180.0;
lon[1] = 180.0;
- hashlen = strlen(geohash);
-
- if (precision < 0 || precision > hashlen)
+ size_t hashlen = strlen(geohash);
+ if (precision < 0 || (size_t)precision > hashlen)
{
- precision = hashlen;
+ precision = (int)hashlen;
}
- for (i = 0; i < precision; i++)
+ for (int i = 0; i < precision; i++)
{
- c = tolower(geohash[i]);
- /* Valid characters are all digits and letters except a, i, l and o */
- if (!(((c >= '0') && (c <= '9')) ||
- ((c >= 'b') && (c <= 'z') && (c != 'i') && (c != 'l') && (c != 'o'))))
+ char c = tolower(geohash[i]);
+
+ /* Valid characters are all digits in base32 */
+ char *base32_pos = strchr(base32, c);
+ if (!base32_pos)
{
lwerror("%s: Invalid character '%c'", __func__, geohash[i]);
return;
}
- cd = strchr(base32, c) - base32;
+ char cd = base32_pos - base32;
- for (j = 0; j < 5; j++)
+ for (size_t j = 0; j < 5; j++)
{
- mask = bits[j];
+ const char bits[] = {16, 8, 4, 2, 1};
+ char mask = bits[j];
if (is_even)
{
lon[!(cd & mask)] = (lon[0] + lon[1]) / 2;
*/
return geohash_point(lon, lat, precision);
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-