From 93cd4eae55a788eb7530fe369db65c7fffc5d931 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Wed, 6 Jan 2021 23:34:29 +0800 Subject: [PATCH] paint.cc car_space_to_full_frame less paramaters (#19676) --- selfdrive/ui/paint.cc | 15 +++++++-------- selfdrive/ui/paint.hpp | 2 +- selfdrive/ui/ui.cc | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/selfdrive/ui/paint.cc b/selfdrive/ui/paint.cc index 4dd7186f40..854eaf907f 100644 --- a/selfdrive/ui/paint.cc +++ b/selfdrive/ui/paint.cc @@ -41,7 +41,7 @@ const mat3 intrinsic_matrix = (mat3){{ // Projects a point in car to space to the corresponding point in full frame // image space. -bool car_space_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, float *out_x, float *out_y, float margin) { +bool car_space_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, vertex_data *out, float margin) { const vec4 car_space_projective = (vec4){{in_x, in_y, in_z, 1.}}; // We'll call the car space point p. // First project into normalized image coordinates with the extrinsics matrix. @@ -52,10 +52,10 @@ bool car_space_to_full_frame(const UIState *s, float in_x, float in_y, float in_ const vec3 KEp = matvecmul3(intrinsic_matrix, Ep); // Project. - *out_x = KEp.v[0] / KEp.v[2]; - *out_y = KEp.v[1] / KEp.v[2]; + out->x = KEp.v[0] / KEp.v[2]; + out->y = KEp.v[1] / KEp.v[2]; - return *out_x >= -margin && *out_x <= s->fb_w + margin && *out_y >= -margin && *out_y <= s->fb_h + margin; + return out->x >= -margin && out->x <= s->fb_w + margin && out->y >= -margin && out->y <= s->fb_h + margin; } @@ -68,11 +68,10 @@ static void ui_draw_text(NVGcontext *vg, float x, float y, const char* string, f static void draw_chevron(UIState *s, float x_in, float y_in, float sz, NVGcolor fillColor, NVGcolor glowColor) { - float x, y; - if (!car_space_to_full_frame(s, x_in, y_in, 0.0, &x, &y)) { - return; - } + vertex_data out; + if (!car_space_to_full_frame(s, x_in, y_in, 0.0, &out)) return; + auto [x, y] = out; sz = std::clamp((sz * 30) / (x_in / 3 + 30), 15.0f, 30.0f); // glow diff --git a/selfdrive/ui/paint.hpp b/selfdrive/ui/paint.hpp index f3b6d1a016..7119579dee 100644 --- a/selfdrive/ui/paint.hpp +++ b/selfdrive/ui/paint.hpp @@ -1,7 +1,7 @@ #pragma once #include "ui.hpp" -bool car_space_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, float *out_x, float *out_y, float margin=0.0); +bool car_space_to_full_frame(const UIState *s, float in_x, float in_y, float in_z, vertex_data *out, float margin=0.0); void ui_draw(UIState *s); void ui_draw_image(NVGcontext *vg, const Rect &r, int image, float alpha); void ui_draw_rect(NVGcontext *vg, float x, float y, float w, float h, NVGcolor color, float r = 0, int width = 0); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index ee75f8ed01..8cb5be63fe 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -113,11 +113,11 @@ static void update_line_data(const UIState *s, const cereal::ModelDataV2::XYZTDa vertex_data *v = &pvd->v[0]; const float margin = 500.0f; for (int i = 0; ((i < TRAJECTORY_SIZE) and (line_x[i] < fmax(MIN_DRAW_DISTANCE, max_distance))); i++) { - v += car_space_to_full_frame(s, line_x[i], -line_y[i] - y_off, -line_z[i] + z_off, &v->x, &v->y, margin); + v += car_space_to_full_frame(s, line_x[i], -line_y[i] - y_off, -line_z[i] + z_off, v, margin); max_idx = i; } for (int i = max_idx; i >= 0; i--) { - v += car_space_to_full_frame(s, line_x[i], -line_y[i] + y_off, -line_z[i] + z_off, &v->x, &v->y, margin); + v += car_space_to_full_frame(s, line_x[i], -line_y[i] + y_off, -line_z[i] + z_off, v, margin); } pvd->cnt = v - pvd->v; assert(pvd->cnt < std::size(pvd->v));