fixed stretching in MapDisplay

This commit is contained in:
Louis Heredero 2024-04-17 17:47:39 +02:00
parent 57808d6f2f
commit 452f6ad041
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 24 additions and 5 deletions

View File

@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CommitMessageInspectionProfile">
<profile version="1.0">
<inspection_tool class="SubjectLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="RIGHT_MARGIN" value="50" />
</inspection_tool>
</profile>
</component>
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>

View File

@ -26,14 +26,26 @@ class MapDisplay(Display):
self.max_lon: float = max_lon
self.min_lat: float = min_lat
self.max_lat: float = max_lat
self._precomputeDisplayValues()
self.cities: list[tuple[Vec2, str, str]] = cities
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)
def _precomputeDisplayValues(self) -> None:
width, height = self.surf.get_size()
self._lon_span = self.max_lon - self.min_lon
self._lat_span = self.max_lat - self.min_lat
r1 = width / self._lon_span
r2 = height / self._lat_span
w, h = self.surf.get_size()
return x * w, h - y * h
self._r = min(r1, r2)
self._ox = (width - self._lon_span * self._r) / 2
self._oy = (height - self._lat_span * self._r) / 2
def real_to_screen(self, lon: float, lat: float) -> tuple[float, float]:
x = (lon - self.min_lon) * self._r + self._ox
y = (lat - self.min_lat) * self._r + self._oy
return x, self.surf.get_height() - y
def draw_path(self, path: Path) -> None:
self.draw_colored_path(path, None)