From 2ec14c2065dfee6f624e592eff2f9d96b784ad61 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Wed, 10 May 2023 11:25:53 +0800 Subject: [PATCH] ui/drawLaneLines: read the accel from the submaster outside of the loop (#28145) * read the accel from the submaster outside of the loop. * const max_idx * remove data copy and converting from list to vector * correct name is len * fix drawing last point * add comment, remove right_points * fix --------- Co-authored-by: Shane Smiskol --- selfdrive/ui/qt/onroad.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 7aac6febaf..7e28fa8113 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -513,17 +513,17 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) { // paint path QLinearGradient bg(0, height(), 0, 0); if (sm["controlsState"].getControlsState().getExperimentalMode()) { - const QVector right_points = scene.track_vertices.mid(0, scene.track_vertices.length() / 2); - - for (int i = 0; i < right_points.length(); i++) { - const auto &acceleration = sm["uiPlan"].getUiPlan().getAccel(); - if (i >= acceleration.size()) break; + // The first half of track_vertices are the points for the right side of the path + // and the indices match the positions of accel from uiPlan + const auto &acceleration = sm["uiPlan"].getUiPlan().getAccel(); + const int max_len = std::min(scene.track_vertices.length() / 2, acceleration.size()); + for (int i = 0; i < max_len; ++i) { // Some points are out of frame - if (right_points[i].y() < 0 || right_points[i].y() > height()) continue; + if (scene.track_vertices[i].y() < 0 || scene.track_vertices[i].y() > height()) continue; // Flip so 0 is bottom of frame - float lin_grad_point = (height() - right_points[i].y()) / height(); + float lin_grad_point = (height() - scene.track_vertices[i].y()) / height(); // speed up: 120, slow down: 0 float path_hue = fmax(fmin(60 + acceleration[i] * 35, 120), 0); @@ -536,7 +536,7 @@ void AnnotatedCameraWidget::drawLaneLines(QPainter &painter, const UIState *s) { bg.setColorAt(lin_grad_point, QColor::fromHslF(path_hue / 360., saturation, lightness, alpha)); // Skip a point, unless next is last - i += (i + 2) < right_points.length() ? 1 : 0; + i += (i + 2) < max_len ? 1 : 0; } } else {