7 /* Int ranges for integerized lat/lon */
8 #define LATLON_MAX 2147483646
9 #define LATLON_MIN -2147483646
10 #define EARTH_RADIUS (3440.06479f)
12 #define MERCATOR_SPAN (-6.28318377773622f)
13 #define MERCATOR_TOP (3.14159188886811f)
15 #define latlon2unit(lat, lon, unitx, unity) { \
17 unitx=lrint((lon + 180.f) * (WORLD_SIZE_UNITS / 360.f)); \
18 tmp=sin(lat * (M_PIl / 180.f)); \
19 unity=lrint((WORLD_SIZE_UNITS / MERCATOR_SPAN) * (log((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP)); \
22 #define unit2latlon(unitx, unity, lat, lon) { \
23 (lon)=((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f; \
24 (lat)=(360.f * (atan(exp(((unity) * (MERCATOR_SPAN / WORLD_SIZE_UNITS)) + MERCATOR_TOP)))) * (1.f / M_PIl) - 90.f; \
36 gchar *DEG_FORMAT_TEXT[DEG_FORMAT_ENUM_COUNT];
38 /** This enum defines the possible units we can use. */
45 gchar *UNITS_TEXT[UNITS_ENUM_COUNT];
47 /* UNITS_CONVERTS, when multiplied, converts from NM. */
48 #define EARTH_RADIUS (3440.06479f)
49 gfloat UNITS_CONVERT[UNITS_ENUM_COUNT];
53 #define lat_format(F, A, B) deg_format((F),(A), (B), 'S', 'N')
54 #define lon_format(F, A, B) deg_format((F),(A), (B), 'W', 'E')
56 void latlon_init(void);
58 gint32 lon2mp_int(gdouble lon);
59 gint32 lat2mp_int(gdouble lat);
61 gdouble mp_int2lon(gint32 lon);
62 gdouble mp_int2lat(gint32 lat);
64 gdouble calculate_distance(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
65 gdouble calculate_ddistance(gint lat1, gint lon1, gint lat2, gint lon2);
66 gulong calculate_idistance(gint lat1, gint lon1, gint lat2, gint lon2);
67 gulong calculate_idistance_cmp(gint lat1, gint lon1, gint lat2, gint lon2);
69 gdouble calculate_course_rad(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
70 gdouble calculate_course(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2);
72 gfloat angle_diff(gfloat a, gfloat b);
74 gboolean distance_point_to_line(gdouble x, gdouble y, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble *d);
76 guint32 xy2tile(guint x, guint y);
77 guint32 lon2x(gdouble lon);
78 guint32 lat2y(gdouble lat);
80 void deg_format(DegFormat degformat, gdouble coor, gchar *scoor, gchar neg_char, gchar pos_char);