diff --git a/selfdrive/common/util.h b/selfdrive/common/util.h index 4f6d4fa19..c8e99faea 100644 --- a/selfdrive/common/util.h +++ b/selfdrive/common/util.h @@ -30,6 +30,13 @@ typedef void (*sighandler_t)(int sig); #endif +const double MILE_TO_KM = 1.609344; +const double KM_TO_MILE = 1. / MILE_TO_KM; +const double MS_TO_KPH = 3.6; +const double MS_TO_MPH = MS_TO_KPH * KM_TO_MILE; +const double METER_TO_MILE = KM_TO_MILE / 1000.0; +const double METER_TO_FOOT = 3.28084; + void set_thread_name(const char* name); int set_realtime_priority(int level); diff --git a/selfdrive/ui/paint.cc b/selfdrive/ui/paint.cc index 363be71a5..1bbbb8379 100644 --- a/selfdrive/ui/paint.cc +++ b/selfdrive/ui/paint.cc @@ -155,7 +155,7 @@ static void ui_draw_vision_maxspeed(UIState *s) { const int SET_SPEED_NA = 255; float maxspeed = (*s->sm)["controlsState"].getControlsState().getVCruise(); const bool is_cruise_set = maxspeed != 0 && maxspeed != SET_SPEED_NA; - if (is_cruise_set && !s->scene.is_metric) { maxspeed *= 0.6225; } + if (is_cruise_set && !s->scene.is_metric) { maxspeed *= KM_TO_MILE; } const Rect rect = {bdr_s * 2, int(bdr_s * 1.5), 184, 202}; ui_fill_rect(s->vg, rect, COLOR_BLACK_ALPHA(100), 30.); @@ -172,7 +172,7 @@ static void ui_draw_vision_maxspeed(UIState *s) { } static void ui_draw_vision_speed(UIState *s) { - const float speed = std::max(0.0, (*s->sm)["carState"].getCarState().getVEgo() * (s->scene.is_metric ? 3.6 : 2.2369363)); + const float speed = std::max(0.0, (*s->sm)["carState"].getCarState().getVEgo() * (s->scene.is_metric ? MS_TO_KPH : MS_TO_MPH)); const std::string speed_str = std::to_string((int)std::nearbyint(speed)); nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE); ui_draw_text(s, s->fb_w/2, 210, speed_str.c_str(), 96 * 2.5, COLOR_WHITE, "sans-bold"); diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index e88879082..6c96edfb3 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -381,8 +381,8 @@ void MapInstructions::updateDistance(float d) { distance_str += " m"; } } else { - float miles = d * METER_2_MILE; - float feet = d * METER_2_FOOT; + float miles = d * METER_TO_MILE; + float feet = d * METER_TO_FOOT; if (feet > 500) { distance_str.setNum(miles, 'f', 1); @@ -597,7 +597,7 @@ void MapETA::updateETA(float s, float s_typical, float d) { num = d / 1000.0; distance_unit->setText("km"); } else { - num = d * METER_2_MILE; + num = d * METER_TO_MILE; distance_unit->setText("mi"); } diff --git a/selfdrive/ui/qt/maps/map_helpers.h b/selfdrive/ui/qt/maps/map_helpers.h index db9b885b7..53a44f42d 100644 --- a/selfdrive/ui/qt/maps/map_helpers.h +++ b/selfdrive/ui/qt/maps/map_helpers.h @@ -9,8 +9,6 @@ #include "common/transformations/orientation.hpp" #include "cereal/messaging/messaging.h" -const float METER_2_MILE = 0.000621371; -const float METER_2_FOOT = 3.28084; #define RAD2DEG(x) ((x) * 180.0 / M_PI) QGeoCoordinate to_QGeoCoordinate(const QMapbox::Coordinate &in); diff --git a/selfdrive/ui/qt/widgets/drive_stats.cc b/selfdrive/ui/qt/widgets/drive_stats.cc index 57c0794a2..bd1dc7176 100644 --- a/selfdrive/ui/qt/widgets/drive_stats.cc +++ b/selfdrive/ui/qt/widgets/drive_stats.cc @@ -9,8 +9,6 @@ #include "selfdrive/ui/qt/request_repeater.h" #include "selfdrive/ui/qt/util.h" -const double MILE_TO_KM = 1.60934; - static QLabel* newLabel(const QString& text, const QString &type) { QLabel* label = new QLabel(text); label->setProperty("type", type);