mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 05:23:41 +08:00
a82935f326
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services. Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Daniel Koepping <elkoled@gmail.com> Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: stef <19478336+stefpi@users.noreply.github.com> Co-authored-by: whoisdomi <dcantu83@gmail.com> Co-authored-by: Intelli <contact@intelli.software> Co-authored-by: pharmacomaniac <blittle65@gmail.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
"""Native line arguments retain logical geometry and current style."""
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
from unittest.mock import Mock, patch
|
|
|
|
import pyray as rl
|
|
|
|
from openpilot.starpilot.ui import onroad_compact_widgets as widgets
|
|
from openpilot.system.ui.lib.application import gui_app
|
|
|
|
|
|
class CompactLineGeometryTests(unittest.TestCase):
|
|
def setUp(self):
|
|
widgets._line_points.cache_clear()
|
|
self.addCleanup(widgets._line_points.cache_clear)
|
|
|
|
def test_native_line_retains_fractional_points_width_and_current_color(self):
|
|
native = Mock()
|
|
api = SimpleNamespace(Vector2=rl.Vector2, rl=SimpleNamespace(DrawLineEx=native))
|
|
first, second = rl.Color(20, 30, 40, 255), rl.Color(100, 110, 120, 63)
|
|
with patch.object(widgets, "rl", api):
|
|
widgets._line(-12.25, 3.5, 40.75, -6.25, first, 4.75)
|
|
widgets._line(-12.25, 3.5, 40.75, -6.25, second, 2)
|
|
start, end, width, color = native.call_args_list[0].args
|
|
self.assertEqual((start.x, start.y, end.x, end.y, width), (-12.25, 3.5, 40.75, -6.25, 4.75))
|
|
self.assertIs(color, first)
|
|
self.assertIs(native.call_args_list[1].args[0], start)
|
|
self.assertIs(native.call_args_list[1].args[1], end)
|
|
self.assertEqual(native.call_args_list[1].args[2], 2)
|
|
self.assertIs(native.call_args_list[1].args[3], second)
|
|
|
|
def test_global_scaling_keeps_cached_points_in_logical_coordinates(self):
|
|
native = Mock()
|
|
api = SimpleNamespace(Vector2=rl.Vector2, rl=SimpleNamespace(DrawLineEx=native))
|
|
with patch.object(widgets, "rl", api):
|
|
for scale in (.5, 1., 2.):
|
|
with patch.object(gui_app, "_scale", scale):
|
|
widgets._line(11.25, 22.5, 33.75, 44., rl.WHITE, 3)
|
|
start, end, width, _ = native.call_args.args
|
|
self.assertEqual((start.x, start.y, end.x, end.y, width), (11.25, 22.5, 33.75, 44., 3))
|
|
self.assertEqual(widgets._line_points.cache_info().currsize, 1)
|
|
|
|
def test_repeated_editor_positions_have_bounded_geometry_retention(self):
|
|
for x in range(512):
|
|
widgets._line_points(x, 2, x + 4, 8)
|
|
self.assertEqual(widgets._line_points.cache_info().currsize, 128)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|