Skip to content

Commit 6884c9d

Browse files
rhttpike3
authored andcommitted
perf: ContinuousSpace: Use math instead of np for get_distance
1 parent ba1784b commit 6884c9d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mesa/space.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# pylint: disable=invalid-name
1515

1616
import itertools
17+
import math
1718

1819
import numpy as np
1920

@@ -890,12 +891,12 @@ def get_distance(self, pos_1: FloatCoordinate, pos_2: FloatCoordinate) -> float:
890891
x1, y1 = pos_1
891892
x2, y2 = pos_2
892893

893-
dx = np.abs(x1 - x2)
894-
dy = np.abs(y1 - y2)
894+
dx = abs(x1 - x2)
895+
dy = abs(y1 - y2)
895896
if self.torus:
896897
dx = min(dx, self.width - dx)
897898
dy = min(dy, self.height - dy)
898-
return np.sqrt(dx * dx + dy * dy)
899+
return math.sqrt(dx * dx + dy * dy)
899900

900901
def torus_adj(self, pos: FloatCoordinate) -> FloatCoordinate:
901902
"""Adjust coordinates to handle torus looping.

0 commit comments

Comments
 (0)