From: Kaj-Michael Lang Date: Wed, 9 Apr 2008 08:31:52 +0000 (+0300) Subject: Add simple angle diff function X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e8de1329b814b2034934eab0c69a61f5e26a3e0;p=mapper Add simple angle diff function --- diff --git a/src/latlon.c b/src/latlon.c index 8827dc1..943510c 100644 --- a/src/latlon.c +++ b/src/latlon.c @@ -56,6 +56,20 @@ UNITS_TEXT[UNITS_MI] = _("mi."); UNITS_TEXT[UNITS_NM] = _("n.m."); } +gfloat +angle_diff(gfloat a, gfloat b) +{ +gfloat tmax, tmin, t; + +tmax=MAX(a,b); +tmin=MIN(a,b); + +t=tmax-tmin; +if (t>180) t-=360; + +return t; +} + static inline gdouble magnitude(gdouble x1, gdouble y1, gdouble x2, gdouble y2) { @@ -244,34 +258,27 @@ gdouble acoor=fabs(coor); switch (degformat) { case DDPDDDDD: g_sprintf(scoor, "%.5f°", coor); - break; + break; case DDPDDDDD_NSEW: - g_sprintf(scoor, "%.5f° %c", acoor, - coor < 0.f ? neg_char : pos_char); - break; - + g_sprintf(scoor, "%.5f° %c", acoor, coor < 0.f ? neg_char : pos_char); + break; case DD_MMPMMM: - g_sprintf(scoor, "%d°%06.3f'", - (int)coor, (acoor - (int)acoor) * 60.0); - break; + g_sprintf(scoor, "%d°%06.3f'", (int)coor, (acoor - (int)acoor) * 60.0); + break; case DD_MMPMMM_NSEW: - g_sprintf(scoor, "%d°%06.3f' %c", - (int)acoor, (acoor - (int)acoor) * 60.0, - coor < 0.f ? neg_char : pos_char); - break; - + g_sprintf(scoor, "%d°%06.3f' %c", (int)acoor, (acoor - (int)acoor) * 60.0, coor < 0.f ? neg_char : pos_char); + break; case DD_MM_SSPS: min = (acoor - (int)acoor) * 60.0; - g_sprintf(scoor, "%d°%02d'%04.1f\"", (int)coor, (int)min, - ((min - (int)min) * 60.0)); - break; + g_sprintf(scoor, "%d°%02d'%04.1f\"", (int)coor, (int)min, ((min - (int)min) * 60.0)); + break; case DD_MM_SSPS_NSEW: min = (acoor - (int)acoor) * 60.0; - g_sprintf(scoor, "%d°%02d'%04.1f\" %c", (int)acoor, (int)min, - ((min - (int)min) * 60.0), - coor < 0.f ? neg_char : pos_char); - break; - default:; + g_sprintf(scoor, "%d°%02d'%04.1f\" %c", (int)acoor, (int)min, ((min - (int)min) * 60.0), coor < 0.f ? neg_char : pos_char); + break; + default: + g_return_if_reached(); + break; } } diff --git a/src/latlon.h b/src/latlon.h index 8f5257d..11bf85c 100644 --- a/src/latlon.h +++ b/src/latlon.h @@ -59,13 +59,17 @@ void latlon_init(void); gint32 lon2mp_int(gdouble lon); gint32 lat2mp_int(gdouble 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); gulong calculate_idistance_cmp(gint lat1, gint lon1, gint lat2, gint lon2); + gdouble calculate_course_rad(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2); gdouble calculate_course(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2); +gfloat angle_diff(gfloat a, gfloat b); + gboolean distance_point_to_line(gdouble x, gdouble y, gdouble x1, gdouble y1, gdouble x2, gdouble y2, gdouble *d); guint32 xy2tile(guint x, guint y);