* @brief Renders the historical GPS trajectory polyline with tail-to-head gradient. */
| 883 | * @brief Renders the historical GPS trajectory polyline with tail-to-head gradient. |
| 884 | */ |
| 885 | void Widgets::GPS::renderTrajectoryPath( |
| 886 | QPainter* painter, const QSize& view, int baseZoom, double scale, const QPointF& centerTileBase) |
| 887 | { |
| 888 | const auto& series = UI::Dashboard::instance().gpsSeries(m_index); |
| 889 | const int tileSize = 256; |
| 890 | const double world = qPow(2.0, baseZoom); |
| 891 | const QPointF cTile = centerTileBase; |
| 892 | |
| 893 | auto project = [&](double lat, double lon) -> QPointF { |
| 894 | QPointF tile = latLonToTile(lat, lon, baseZoom); |
| 895 | |
| 896 | double dx = tile.x() - cTile.x(); |
| 897 | dx -= std::round(dx / world) * world; |
| 898 | |
| 899 | QPointF delta(dx, tile.y() - cTile.y()); |
| 900 | return {view.width() * 0.5 + delta.x() * tileSize * scale, |
| 901 | view.height() * 0.5 + delta.y() * tileSize * scale}; |
| 902 | }; |
| 903 | |
| 904 | QVector<QPointF> path; |
| 905 | auto pushIfValid = [&](double lat, double lon) { |
| 906 | if (std::isnan(lat) || std::isnan(lon) || DSP::isZero(lat) || DSP::isZero(lon)) |
| 907 | return; |
| 908 | |
| 909 | path.append(project(lat, lon)); |
| 910 | }; |
| 911 | for (size_t i = 0; i < series.latitudes.size(); ++i) |
| 912 | pushIfValid(series.latitudes[i], series.longitudes[i]); |
| 913 | |
| 914 | pushIfValid(m_latitude, m_longitude); |
| 915 | |
| 916 | const QRectF vp(0, 0, view.width(), view.height()); |
| 917 | const bool v = |
| 918 | std::any_of(path.cbegin(), path.cend(), [&](const QPointF& p) { return vp.contains(p); }); |
| 919 | |
| 920 | if (!v || path.size() <= 1) |
| 921 | return; |
| 922 | |
| 923 | QLinearGradient grad(path.first(), path.last()); |
| 924 | grad.setColorAt(0.0, m_lineTailColor); |
| 925 | grad.setColorAt(1.0, m_lineHeadColor); |
| 926 | |
| 927 | QPen pen(QBrush(grad), 2); |
| 928 | painter->setPen(pen); |
| 929 | |
| 930 | for (int i = 1; i < path.size(); ++i) { |
| 931 | const QPointF& p1 = path[i - 1]; |
| 932 | const QPointF& p2 = path[i]; |
| 933 | painter->drawLine(p1, p2); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * @brief Renders the current-position indicator (halo, border, dot), wrapped 3x. |
nothing calls this directly
no test coverage detected