From 352b23ddf594c74c94f3d467de38202cc831aeb9 Mon Sep 17 00:00:00 2001 From: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Date: Thu, 3 Sep 2026 01:09:51 -0400 Subject: [PATCH] Not quite a pollo bowl --- selfdrive/ui/lib/starpilot_visuals.py | 10 ++++++++++ .../ui/onroad/starpilot/starpilot_border.py | 8 +++++--- .../onroad/starpilot/starpilot_onroad_view.py | 7 +++++-- selfdrive/ui/tests/test_starpilot_visuals.py | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/selfdrive/ui/lib/starpilot_visuals.py b/selfdrive/ui/lib/starpilot_visuals.py index eb29d1dbe..1669eeb84 100644 --- a/selfdrive/ui/lib/starpilot_visuals.py +++ b/selfdrive/ui/lib/starpilot_visuals.py @@ -7,6 +7,16 @@ import pyray as rl from openpilot.common.params import Params +_BORDER_ROUNDNESS = 0.12 +_BORDER_RADIUS_MULTIPLE = 3.0 + + +def get_border_roundness(rect: rl.Rectangle, border_width: float) -> float: + """Keep a rectangular camera inset inside the rounded frame at thin widths.""" + min_dimension = max(1.0, min(rect.width, rect.height)) + return min(_BORDER_ROUNDNESS, 2.0 * _BORDER_RADIUS_MULTIPLE * border_width / min_dimension) + + def blend_colors(a: rl.Color, b: rl.Color, f: float) -> rl.Color: h0, s0, v0 = (hsv0 := rl.color_to_hsv(a)).x, hsv0.y, hsv0.z h1, s1, v1 = (hsv1 := rl.color_to_hsv(b)).x, hsv1.y, hsv1.z diff --git a/selfdrive/ui/onroad/starpilot/starpilot_border.py b/selfdrive/ui/onroad/starpilot/starpilot_border.py index 1cae802e8..c1d49f2fc 100644 --- a/selfdrive/ui/onroad/starpilot/starpilot_border.py +++ b/selfdrive/ui/onroad/starpilot/starpilot_border.py @@ -11,6 +11,7 @@ from openpilot.selfdrive.ui.ui_state import ui_state from openpilot.selfdrive.ui.lib.starpilot_status import ( CEM_OVERRIDE_COLOR, ENGAGED_COLOR, EXPERIMENTAL_COLOR, TRAFFIC_COLOR ) +from openpilot.selfdrive.ui.lib.starpilot_visuals import get_border_roundness @@ -218,6 +219,7 @@ def get_traffic_border_colors() -> tuple[rl.Color, rl.Color] | None: def render_background_effects(rect: rl.Rectangle, border_width: float): global _smoothed_steer sm = ui_state.sm + border_roundness = get_border_roundness(rect, border_width) # 1. Turn Signal and Blind Spot indicators colors = get_traffic_border_colors() @@ -225,11 +227,11 @@ def render_background_effects(rect: rl.Rectangle, border_width: float): left_color, right_color = colors if left_color.a > 0: rl.begin_scissor_mode(int(rect.x), int(rect.y), int(rect.width // 2), int(rect.height)) - rl.draw_rectangle_rounded(rect, 0.12, 10, left_color) + rl.draw_rectangle_rounded(rect, border_roundness, 10, left_color) rl.end_scissor_mode() if right_color.a > 0: rl.begin_scissor_mode(int(rect.x + rect.width // 2), int(rect.y), int(rect.width // 2), int(rect.height)) - rl.draw_rectangle_rounded(rect, 0.12, 10, right_color) + rl.draw_rectangle_rounded(rect, border_roundness, 10, right_color) rl.end_scissor_mode() # 2. Steering Torque Border @@ -262,7 +264,7 @@ def render_background_effects(rect: rl.Rectangle, border_width: float): else: rl.begin_scissor_mode(int(rect.x + rect.width - border_width), y_pos, int(border_width), int(visible_height)) - rl.draw_rectangle_rounded(rect, 0.12, 10, col) + rl.draw_rectangle_rounded(rect, border_roundness, 10, col) rl.end_scissor_mode() diff --git a/selfdrive/ui/onroad/starpilot/starpilot_onroad_view.py b/selfdrive/ui/onroad/starpilot/starpilot_onroad_view.py index ec504fe1e..5fd40bb8a 100644 --- a/selfdrive/ui/onroad/starpilot/starpilot_onroad_view.py +++ b/selfdrive/ui/onroad/starpilot/starpilot_onroad_view.py @@ -21,6 +21,7 @@ from openpilot.selfdrive.ui.onroad.starpilot.weather_icon import render_weather_ from openpilot.selfdrive.ui.lib.starpilot_status import ( get_screen_edge_color, ) +from openpilot.selfdrive.ui.lib.starpilot_visuals import get_border_roundness from openpilot.starpilot.common.favorite_slots import ( build_favorite_slot_options, filter_favorite_slot_options, @@ -100,8 +101,9 @@ class StarPilotOnroadView(AugmentedRoadView): def _render(self, rect: rl.Rectangle): border_width = self._get_border_width() + border_roundness = get_border_roundness(rect, border_width) border_color = get_pulse_glide_border_color(ui_state.sm, get_screen_edge_color(ui_state)) - rl.draw_rectangle_rounded(rect, 0.12, 10, border_color) + rl.draw_rectangle_rounded(rect, border_roundness, 10, border_color) render_background_effects(rect, border_width) # The favorite menu has first claim on the lower-left gesture. Filtering @@ -159,7 +161,8 @@ class StarPilotOnroadView(AugmentedRoadView): def _draw_border(self, rect: rl.Rectangle): border_width = self._get_border_width() - rl.draw_rectangle_rounded_lines_ex(rect, 0.12, 10, border_width, rl.BLACK) + border_roundness = get_border_roundness(rect, border_width) + rl.draw_rectangle_rounded_lines_ex(rect, border_roundness, 10, border_width, rl.BLACK) border_rect = rl.Rectangle(rect.x + border_width, rect.y + border_width, rect.width - 2 * border_width, rect.height - 2 * border_width) render_overlay(border_rect, border_width) diff --git a/selfdrive/ui/tests/test_starpilot_visuals.py b/selfdrive/ui/tests/test_starpilot_visuals.py index 45cf8a1dc..cb5ff7237 100644 --- a/selfdrive/ui/tests/test_starpilot_visuals.py +++ b/selfdrive/ui/tests/test_starpilot_visuals.py @@ -1,6 +1,8 @@ import importlib.util +import math import unittest from pathlib import Path +from types import SimpleNamespace MODULE_PATH = Path(__file__).resolve().parents[1] / "lib" / "starpilot_visuals.py" @@ -9,6 +11,7 @@ MODULE = importlib.util.module_from_spec(SPEC) assert SPEC is not None and SPEC.loader is not None SPEC.loader.exec_module(MODULE) lead_indicator_enabled = MODULE.lead_indicator_enabled +get_border_roundness = MODULE.get_border_roundness class FakeParams: @@ -29,6 +32,21 @@ class FakeParams: class TestStarPilotVisuals(unittest.TestCase): + def test_border_roundness_contains_camera_corner(self): + rect = SimpleNamespace(width=2160, height=1080) + base_width = 30 + min_dimension = min(rect.width, rect.height) + + for scale in (25, 50, 65, 100, 250): + border_width = round(base_width * scale / 100) + roundness = get_border_roundness(rect, border_width) + radius = roundness * min_dimension / 2 + self.assertLessEqual(math.sqrt(2) * (radius - border_width), radius) + + def test_border_roundness_preserves_stock_geometry(self): + rect = SimpleNamespace(width=2160, height=1080) + self.assertAlmostEqual(get_border_roundness(rect, 30), 0.12) + def test_lead_indicator_enabled_by_default(self): self.assertTrue(lead_indicator_enabled(FakeParams()))