From 72d81959438aca7f020586aff69bda08d4a59f53 Mon Sep 17 00:00:00 2001 From: XANTRONIX Industrial Date: Sun, 2 Mar 2025 13:46:50 -0500 Subject: [PATCH] Add sample_to_graph() to make code easier to read --- lib/xmet/hodograph.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/xmet/hodograph.py b/lib/xmet/hodograph.py index b3552ee..008d770 100644 --- a/lib/xmet/hodograph.py +++ b/lib/xmet/hodograph.py @@ -29,12 +29,20 @@ class Hodograph(): self.height = min(width, height) self.radius = min(width, height) * self.zoom + def sample_to_graph(self, wind_speed: dir, wind_dir: float) -> tuple: + r = self.radius * (wind_speed / WIND_SPEED_MAX) + + x = r * math.cos(radians(wind_dir)) + y = r * math.sin(radians(wind_dir)) + + return x, y + def sample_to_screen(self, wind_speed: dir, wind_dir: float) -> tuple: - r = self.radius * min(wind_speed, WIND_SPEED_MAX) / WIND_SPEED_MAX + gx, gy = self.sample_to_graph(wind_speed, wind_dir) return ( - self.offset_x * self.width + r * math.cos(radians(wind_dir)), - self.offset_y * self.height + r * math.sin(radians(wind_dir)) + self.offset_x * self.width + gx, + self.offset_y * self.height + gy ) def draw_speed_lines(self, cr: cairo.Context, x, y):