From: Kaj-Michael Lang Date: Tue, 13 May 2008 15:57:35 +0000 (+0300) Subject: LatLon helpers: Small cleanups X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7dfe252c49a9b258c02dc11d7d9f9e0caa71adb2;p=mapper LatLon helpers: Small cleanups --- diff --git a/src/latlon.c b/src/latlon.c index 1ce5b6a..dceab08 100644 --- a/src/latlon.c +++ b/src/latlon.c @@ -36,12 +36,6 @@ #include "latlon.h" #include "osm.h" -/* Int ranges for integerized lat/lon */ -#define LATLON_MAX 2147483646 -#define LATLON_MIN -2147483646 - -#define EARTH_RADIUS (3440.06479f) - void latlon_init(void) { @@ -154,13 +148,13 @@ return lrint(lon/180*LATLON_MAX); } gdouble -mp_int2lon(gint lon) +mp_int2lon(gint32 lon) { return (gdouble)lon/LATLON_MAX*180; } gdouble -mp_int2lat(gint lat) +mp_int2lat(gint32 lat) { return 0; } diff --git a/src/latlon.h b/src/latlon.h index 01b722d..683daa1 100644 --- a/src/latlon.h +++ b/src/latlon.h @@ -9,22 +9,19 @@ #define LATLON_MIN -2147483646 #define EARTH_RADIUS (3440.06479f) -#define PI (3.14159265358979323846f) #define MERCATOR_SPAN (-6.28318377773622f) #define MERCATOR_TOP (3.14159188886811f) #define latlon2unit(lat, lon, unitx, unity) { \ gdouble tmp; \ - unitx = (lon + 180.f) * (WORLD_SIZE_UNITS / 360.f) + 0.5f; \ - tmp = sinf(lat * (PI / 180.f)); \ - unity = 0.5f + (WORLD_SIZE_UNITS / MERCATOR_SPAN) \ - * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP); \ + unitx=lrint((lon + 180.f) * (WORLD_SIZE_UNITS / 360.f)); \ + tmp=sin(lat * (M_PIl / 180.f)); \ + unity=lrint((WORLD_SIZE_UNITS / MERCATOR_SPAN) * (log((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP)); \ } #define unit2latlon(unitx, unity, lat, lon) { \ - (lon) = ((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f; \ - (lat) = (360.f * (atanf(expf(((unity) * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) \ - + MERCATOR_TOP)))) * (1.f / PI) - 90.f; \ + (lon)=((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f; \ + (lat)=(360.f * (atan(exp(((unity) * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) + MERCATOR_TOP)))) * (1.f / M_PIl) - 90.f; \ } typedef enum { @@ -61,6 +58,9 @@ void latlon_init(void); gint32 lon2mp_int(gdouble lon); gint32 lat2mp_int(gdouble lat); +gdouble mp_int2lon(gint32 lon); +gdouble mp_int2lat(gint32 lat); + gdouble calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2); gdouble calculate_ddistance(gint lat1, gint lon1, gint lat2, gint lon2); gulong calculate_idistance(gint lat1, gint lon1, gint lat2, gint lon2);