#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 {
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);