mirror of https://github.com/commaai/openpilot.git
ui/map: better rounding for distances (#29151)
* round distance
* use same format in ETA
* remove vanish
* restore translate
* use nearbyint
* update translations
* mark finished
* consistent style
* we don't include this anywhere in ui, needed?
* fix missing std
---------
Co-authored-by: Shane Smiskol <shane@smiskol.com>
old-commit-hash: efefcfdca5
This commit is contained in:
parent
709850e304
commit
3078da290d
|
@ -3,6 +3,7 @@
|
|||
#include <QDateTime>
|
||||
#include <QPainter>
|
||||
|
||||
#include "selfdrive/ui/qt/maps/map_helpers.h"
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
const float MANEUVER_TRANSITION_THRESHOLD = 10;
|
||||
|
@ -43,9 +44,7 @@ void MapETA::updateETA(float s, float s_typical, float d) {
|
|||
color = "#DAA725";
|
||||
|
||||
// Distance
|
||||
float num = uiState()->scene.is_metric ? (d / 1000.0) : (d * METER_TO_MILE);
|
||||
auto distance = std::pair{QString::number(num, 'f', num < 100 ? 1 : 0),
|
||||
uiState()->scene.is_metric ? tr("km") : tr("mi")};
|
||||
auto distance = map_format_distance(d, uiState()->scene.is_metric);
|
||||
|
||||
eta_doc.setHtml(QString(R"(<body><table><tr style="vertical-align:bottom;"><td><b>%1</b></td><td>%2</td>
|
||||
<td style="padding-left:40px;color:%3;"><b>%4</b></td><td style="padding-right:40px;color:%3;">%5</td>
|
||||
|
|
|
@ -129,6 +129,23 @@ std::optional<QMapbox::Coordinate> coordinate_from_param(const std::string ¶
|
|||
}
|
||||
}
|
||||
|
||||
// return {distance, unit}
|
||||
std::pair<QString, QString> map_format_distance(float d, bool is_metric) {
|
||||
auto round_distance = [](float d) -> float {
|
||||
return (d > 10) ? std::nearbyint(d) : std::nearbyint(d * 10) / 10.0;
|
||||
};
|
||||
|
||||
d = std::max(d, 0.0f);
|
||||
if (is_metric) {
|
||||
return (d > 500) ? std::pair{QString::number(round_distance(d / 1000)), QObject::tr("km")}
|
||||
: std::pair{QString::number(50 * std::nearbyint(d / 50)), QObject::tr("m")};
|
||||
} else {
|
||||
float feet = d * METER_TO_FOOT;
|
||||
return (feet > 500) ? std::pair{QString::number(round_distance(d * METER_TO_MILE)), QObject::tr("mi")}
|
||||
: std::pair{QString::number(50 * std::nearbyint(d / 50)), QObject::tr("ft")};
|
||||
}
|
||||
}
|
||||
|
||||
double angle_difference(double angle1, double angle2) {
|
||||
double diff = fmod(angle2 - angle1 + 180.0, 360.0) - 180.0;
|
||||
return diff < -180.0 ? diff + 360.0 : diff;
|
||||
|
|
|
@ -25,6 +25,6 @@ QMapbox::CoordinatesCollections coordinate_to_collection(const QMapbox::Coordina
|
|||
QMapbox::CoordinatesCollections capnp_coordinate_list_to_collection(const capnp::List<cereal::NavRoute::Coordinate>::Reader &coordinate_list);
|
||||
QMapbox::CoordinatesCollections coordinate_list_to_collection(const QList<QGeoCoordinate> &coordinate_list);
|
||||
QList<QGeoCoordinate> polyline_to_coordinate_list(const QString &polylineString);
|
||||
|
||||
std::optional<QMapbox::Coordinate> coordinate_from_param(const std::string ¶m);
|
||||
std::pair<QString, QString> map_format_distance(float d, bool is_metric);
|
||||
double angle_difference(double angle1, double angle2);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <QDir>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "selfdrive/ui/qt/maps/map_helpers.h"
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
const QString ICON_SUFFIX = ".png";
|
||||
|
@ -63,18 +64,6 @@ void MapInstructions::buildPixmapCache() {
|
|||
}
|
||||
}
|
||||
|
||||
QString MapInstructions::getDistance(float d) {
|
||||
d = std::max(d, 0.0f);
|
||||
if (uiState()->scene.is_metric) {
|
||||
return (d > 500) ? QString::number(d / 1000, 'f', 1) + tr(" km")
|
||||
: QString::number(50 * qRound(d / 50)) + tr(" m");
|
||||
} else {
|
||||
float feet = d * METER_TO_FOOT;
|
||||
return (feet > 500) ? QString::number(d * METER_TO_MILE, 'f', 1) + tr(" mi")
|
||||
: QString::number(50 * qRound(feet / 50)) + tr(" ft");
|
||||
}
|
||||
}
|
||||
|
||||
void MapInstructions::updateInstructions(cereal::NavInstruction::Reader instruction) {
|
||||
setUpdatesEnabled(false);
|
||||
|
||||
|
@ -85,7 +74,9 @@ void MapInstructions::updateInstructions(cereal::NavInstruction::Reader instruct
|
|||
primary->setText(primary_str);
|
||||
secondary->setVisible(secondary_str.length() > 0);
|
||||
secondary->setText(secondary_str);
|
||||
distance->setText(getDistance(instruction.getManeuverDistance()));
|
||||
|
||||
auto distance_str_pair = map_format_distance(instruction.getManeuverDistance(), uiState()->scene.is_metric);
|
||||
distance->setText(QString("%1 %2").arg(distance_str_pair.first, distance_str_pair.second));
|
||||
|
||||
// Show arrow with direction
|
||||
QString type = QString::fromStdString(instruction.getManeuverType());
|
||||
|
|
|
@ -31,6 +31,5 @@ private:
|
|||
public:
|
||||
MapInstructions(QWidget * parent=nullptr);
|
||||
void buildPixmapCache();
|
||||
QString getDistance(float d);
|
||||
void updateInstructions(cereal::NavInstruction::Reader instruction);
|
||||
};
|
||||
|
|
|
@ -354,33 +354,6 @@
|
|||
<source>hr</source>
|
||||
<translation>std</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> fuß</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -620,6 +593,22 @@
|
|||
<numerusform>vor %n Tagen</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>fuß</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
|
@ -354,33 +354,6 @@
|
|||
<source>hr</source>
|
||||
<translation>h</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -621,6 +594,22 @@
|
|||
<numerusform>il y a %n jours</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
|
@ -353,33 +353,6 @@
|
|||
<source>hr</source>
|
||||
<translation>時間</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>キロメートル</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>マイル</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> キロメートル</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> メートル</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> マイル</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> フィート</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -616,6 +589,22 @@
|
|||
<numerusform>%n 日前</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>キロメートル</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>メートル</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>マイル</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>フィート</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
|
@ -353,33 +353,6 @@
|
|||
<source>hr</source>
|
||||
<translation>시간</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -617,6 +590,22 @@
|
|||
<numerusform>%n 일전</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
|
@ -354,33 +354,6 @@
|
|||
<source>hr</source>
|
||||
<translation>hr</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> milha</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> pés</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -621,6 +594,22 @@
|
|||
<numerusform>há %n dias</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>milha</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>pés</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
|
@ -353,33 +353,6 @@
|
|||
<source>hr</source>
|
||||
<translation>ชม.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>กม.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>ไมล์</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> กม.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> ม.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> ไมล์</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> ฟุต</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -617,6 +590,22 @@
|
|||
<numerusform>%n วันที่แล้ว</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>กม.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>ม.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>ไมล์</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>ฟุต</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
|
@ -353,33 +353,6 @@
|
|||
<source>hr</source>
|
||||
<translation>saat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mil</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> mil</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -616,6 +589,22 @@
|
|||
<numerusform>%n gün önce</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mil</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
|
@ -353,33 +353,6 @@
|
|||
<source>hr</source>
|
||||
<translation>小时</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -617,6 +590,22 @@
|
|||
<numerusform>%n 天前</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
|
@ -353,33 +353,6 @@
|
|||
<source>hr</source>
|
||||
<translation>小時</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapInstructions</name>
|
||||
<message>
|
||||
<source> km</source>
|
||||
<translation> km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> m</source>
|
||||
<translation> m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> mi</source>
|
||||
<translation> mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source> ft</source>
|
||||
<translation> ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MapSettings</name>
|
||||
|
@ -617,6 +590,22 @@
|
|||
<numerusform>%n 天前</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>mi</source>
|
||||
<translation>mi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>ft</source>
|
||||
<translation>ft</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Reset</name>
|
||||
|
|
Loading…
Reference in New Issue