From c0063a5d750e79daebbc7ad538012633d16a26c8 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 15 Apr 2024 22:27:00 +0200 Subject: [PATCH] integrated Path in MapDisplay --- map_display.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/map_display.py b/map_display.py index a09e081..e0495e6 100644 --- a/map_display.py +++ b/map_display.py @@ -2,6 +2,8 @@ from typing import Optional import pygame +from path import Path + class MapDisplay: PATH_WIDTH = 5 @@ -13,18 +15,23 @@ class MapDisplay: self.min_lon: float = min_lon self.max_lon: float = max_lon - def real_to_screen(self, lat: float, lon: float) -> tuple[float, float]: + def real_to_screen(self, lon: float, lat: float) -> tuple[float, float]: x = (lon - self.min_lon) / (self.max_lon - self.min_lon) y = (lat - self.min_lat) / (self.max_lat - self.min_lat) w, h = self.surf.get_size() return x * w, y * h - def draw_path(self, path: list[tuple[int, int]], colors: Optional[list[tuple[int, int, int]]]) -> None: - for i, (lat, lon) in enumerate(path): - x, y = self.real_to_screen(lat, lon) + def draw_path(self, path: Path) -> None: + self.draw_colored_path(path, None) + + def draw_colored_path(self, path: Path, colors: Optional[list[tuple[int, int, int]]] = None) -> None: + for i, pt in enumerate(path.points): + lon = pt.x + lat = pt.y + x, y = self.real_to_screen(lon, lat) col = (255, 255, 255) if colors is None else colors[i] pygame.draw.circle(self.surf, col, (x, y), self.PATH_WIDTH) - def draw_segment(self, path: list[tuple[int, int]], start_i: int, end_i: int) -> None: + def draw_segment(self, path: Path, start_i: int, end_i: int) -> None: raise NotImplementedError