summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Curley <charlescurley@charlescurley.com>2017-11-25 12:02:08 -0700
committerCharles Curley <charlescurley@charlescurley.com>2017-11-25 12:02:08 -0700
commite64dcdf46bdc8de18deed9c2509607369255686c (patch)
tree43d9c2541e2fadb52d87c131a4b023d2085b049f
parent7030908f604d268cf38baee920fe66e98da8ec72 (diff)
downloadnavit-e64dcdf46bdc8de18deed9c2509607369255686c.tar.gz
fix:gtk:Fix imperial factors. Again.
Another go at fixing imperial measures. This is ready for testing on a different machine, but not for a pull request. Also, some improvements in some comments.
-rw-r--r--navit/gui/gtk/gui_gtk_statusbar.c2
-rw-r--r--navit/navigation.c16
-rw-r--r--navit/navigation.h12
-rw-r--r--navit/navit.c12
4 files changed, 27 insertions, 15 deletions
diff --git a/navit/gui/gtk/gui_gtk_statusbar.c b/navit/gui/gtk/gui_gtk_statusbar.c
index 5497f9a9c..6e5c9980d 100644
--- a/navit/gui/gtk/gui_gtk_statusbar.c
+++ b/navit/gui/gtk/gui_gtk_statusbar.c
@@ -87,7 +87,7 @@ statusbar_route_update(struct statusbar_priv *this, struct navit *navit, struct
struct map_rect *mr=NULL;
struct item *item=NULL;
struct attr attr;
- double route_len=0;
+ double route_len=0; /* Distance to destination. We get it in kilometers. */
time_t eta;
struct tm *eta_tm=NULL;
char buffer[128];
diff --git a/navit/navigation.c b/navit/navigation.c
index 0812093d1..cc1b47bc2 100644
--- a/navit/navigation.c
+++ b/navit/navigation.c
@@ -1014,11 +1014,11 @@ round_distance_reduced( int dist )
* 'imperial' if set distinguishes the distance statement between miles and feet. Maximum distance in feet is 500.
* 'vocabulary_distances' if set constrains the distance values to a set of simple pronounceable numbers.
*
-* @param nav The navigation object.
-* @param dist Distance in meters.
-* @param type The type of announcement precision.
-* @param is_length 1 for length statement, 0 for distance statement.
-* @return String with length/distance statement.
+* @param nav The navigation object.
+* @param dist_meters Distance in meters.
+* @param type The type of announcement precision.
+* @param is_length 1 for length statement, 0 for distance statement.
+* @return String with length/distance statement.
*/
static char *
get_distance_str(struct navigation *nav, int dist_meters, enum attr_type type, int is_length)
@@ -1058,7 +1058,7 @@ get_distance_str(struct navigation *nav, int dist_meters, enum attr_type type, i
return g_strdup_printf(_("in %d feet"), dist_feet);
}
- int dist_miles = (double) dist_meters / (double)METERS_PER_MILE + 0.5;
+ int dist_miles = (double) dist_meters * (double)METERS_TO_MILES + 0.5;
if (vocabulary == 0)
{
@@ -1066,10 +1066,10 @@ get_distance_str(struct navigation *nav, int dist_meters, enum attr_type type, i
dist_miles = round_distance_reduced(dist_miles);
}
- if ((dist_meters < METERS_PER_MILE) && (vocabulary > 0))
+ if ((dist_meters < METERS_TO_MILES) && (vocabulary > 0))
{
/* values smaller than one need extra treatment for one decimal place. For reduced vocabulary it shall remain 'one'. */
- int rem = (((double)dist_meters / (double)METERS_PER_MILE) + 0.05) * 10.0;
+ int rem = (((double)dist_meters * (double)METERS_TO_MILES) + 0.05) * 10.0;
dist_miles= 0;
if (is_length)
return g_strdup_printf(_("%d.%d miles"), dist_miles, rem);
diff --git a/navit/navigation.h b/navit/navigation.h
index 789d4fcbf..0651dbc79 100644
--- a/navit/navigation.h
+++ b/navit/navigation.h
@@ -23,8 +23,16 @@
#define FEET_PER_METER 3.2808399
#define FEET_PER_MILE 5280
#define KILOMETERS_TO_MILES 0.62137119 /* Kilometers to miles */
-#define METERS_PER_MILE 1/(KILOMETERS_TO_MILES/1000.00)
-#define MPS_TO_KPH 3.6 /* Meters per second to klicks/hr */
+
+/* It appears that distances to be displayed, such as distances to
+ * maneuvers, are in meters. Multiply that by METERS_PER_MILE and you
+ * have miles. */
+#define METERS_TO_MILES (KILOMETERS_TO_MILES/1000.0) /* Meters to miles */
+/* #define METERS_PER_MILE (1000.0/KILOMETERS_TO_MILES) */
+
+/* Meters per second to kilometers per hour. GPSD delivers speeds in
+ * meters per second. */
+#define MPS_TO_KPH 3.6
#ifdef __cplusplus
extern "C" {
diff --git a/navit/navit.c b/navit/navit.c
index 768fb7d3b..a32de161e 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -1975,14 +1975,15 @@ navit_window_roadbook_update(struct navit *this_)
param[0].value=_("Position");
param[0].name=_("Command");
+ /* Distance to the next maneuver. */
item_attr_get(item, attr_length, &attr);
- dbg(lvl_info, "Length=%ld\n", attr.u.num);
+ dbg(lvl_info, "Length=%ld in meters\n", attr.u.num);
param[1].name=_("Length");
if ( attr.u.num >= 2000 )
{
param[1].value=g_strdup_printf("%5.1f %s",
- imperial == TRUE ? (float)attr.u.num / (METERS_PER_MILE/1000.00) : (float)attr.u.num / 1000,
+ imperial == TRUE ? (float)attr.u.num * METERS_TO_MILES : (float)attr.u.num / 1000,
imperial == TRUE ? _("mi") : _("km")
);
}
@@ -1994,6 +1995,7 @@ navit_window_roadbook_update(struct navit *this_)
);
}
+ /* Time to next maneuver. */
item_attr_get(item, attr_time, &attr);
dbg(lvl_info, "Time=%ld\n", attr.u.num);
secs=attr.u.num/10;
@@ -2007,13 +2009,14 @@ navit_window_roadbook_update(struct navit *this_)
param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
}
+ /* Distance from next maneuver to destination. */
item_attr_get(item, attr_destination_length, &attr);
- dbg(lvl_info, "Destlength=%ld\n", attr.u.num);
+ dbg(lvl_info, "Destlength=%ld in meters.\n", attr.u.num);
param[3].name=_("Destination Length");
if ( attr.u.num >= 2000 )
{
param[3].value=g_strdup_printf("%5.1f %s",
- imperial == TRUE ? (float)attr.u.num / METERS_PER_MILE : (float)attr.u.num / 1000,
+ imperial == TRUE ? (float)attr.u.num * METERS_TO_MILES : (float)attr.u.num / 1000,
imperial == TRUE ? _("mi") : _("km")
);
}
@@ -2025,6 +2028,7 @@ navit_window_roadbook_update(struct navit *this_)
);
}
+ /* Time from next maneuver to destination. */
item_attr_get(item, attr_destination_time, &attr);
dbg(lvl_info, "Desttime=%ld\n", attr.u.num);
secs=attr.u.num/10;