From 5a728385d2f2fcb146ebe58def8c63b30e859c8b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 28 Apr 2022 21:50:25 +0200 Subject: [PATCH] added function that calulates the closest shelf --- Package.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Package.py b/Package.py index 2ffb153..1c6b1b2 100644 --- a/Package.py +++ b/Package.py @@ -1,10 +1,10 @@ -import numpy as np import glob2 import pygame import random from Field import Field from Global_variables import Global_variables as G_var from Package_types import Package_types +import math class Package(Field): @@ -34,3 +34,13 @@ class Package(Field): elif package_type == Package_types.priority: color = (10, 34, 255) return color + + def choose_the_closest_shelf(self, shelves): + array = [] + for shelf in shelves: + if shelf.type == self.type: + segment = math.sqrt((shelf.x - self.x)**2 + (shelf.y - self.y)**2) + array.append((segment, shelf)) + array.sort(key=lambda y: y[0]) + print(array) + return array[0]