From 6884c9d1962d16249e4ba74c896266dbce652f57 Mon Sep 17 00:00:00 2001 From: rht Date: Sat, 26 Mar 2022 06:26:49 -0400 Subject: [PATCH] perf: ContinuousSpace: Use math instead of np for get_distance --- mesa/space.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mesa/space.py b/mesa/space.py index f9756fc9c60..cf2de4c55ff 100644 --- a/mesa/space.py +++ b/mesa/space.py @@ -14,6 +14,7 @@ # pylint: disable=invalid-name import itertools +import math import numpy as np @@ -890,12 +891,12 @@ def get_distance(self, pos_1: FloatCoordinate, pos_2: FloatCoordinate) -> float: x1, y1 = pos_1 x2, y2 = pos_2 - dx = np.abs(x1 - x2) - dy = np.abs(y1 - y2) + dx = abs(x1 - x2) + dy = abs(y1 - y2) if self.torus: dx = min(dx, self.width - dx) dy = min(dy, self.height - dy) - return np.sqrt(dx * dx + dy * dy) + return math.sqrt(dx * dx + dy * dy) def torus_adj(self, pos: FloatCoordinate) -> FloatCoordinate: """Adjust coordinates to handle torus looping.