From 5e2c87b2ed3fe720d4434a4ed258cd9d220ce37e Mon Sep 17 00:00:00 2001 From: ThisBirchWood Date: Tue, 11 Mar 2025 21:50:39 +0100 Subject: [PATCH] UPDATE: Moved mapping function to class --- coordinate_manager.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/coordinate_manager.py b/coordinate_manager.py index 9355396..ab86d85 100644 --- a/coordinate_manager.py +++ b/coordinate_manager.py @@ -1,12 +1,17 @@ -def mapped_value(value, in_min, in_max, out_min, out_max): - return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min +# Description: This file contains the CoordinateManager class which is responsible for converting coordinates to pixels and vice versa. class CoordinateManager: def __init__(self, width, height): self.width = width self.height = height + def mapped_value(self, value, in_min, in_max, out_min, out_max): + return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min + def coord_to_pixel(self, x, y): - mapped_x = mapped_value(x, -4000, 4000, 0, self.width) - mapped_y = mapped_value(y, -4000, 4000, 0, self.height) - return mapped_x, mapped_y \ No newline at end of file + mapped_x = self.mapped_value(x, -3000, 3000, 0, self.width) + mapped_y = self.mapped_value(y, -3000, 3000, 0, self.height) + return mapped_x, mapped_y + + def get_top_left(self, width, height, scale): + return (width - scale) // 2, (height - scale) // 2 \ No newline at end of file