diff --git a/agents.py b/agents.py index a5bf376ca..742cd6c40 100644 --- a/agents.py +++ b/agents.py @@ -35,7 +35,7 @@ # # Speed control in GUI does not have any effect -- fix it. -from grid import distance2, turn_heading +from grid import distance_squared, turn_heading from statistics import mean import random @@ -397,8 +397,8 @@ def things_near(self, location, radius=None): if radius is None: radius = self.perceptible_distance radius2 = radius * radius - return [(thing, radius2 - distance2(location, thing.location)) for thing in self.things - if distance2(location, thing.location) <= radius2] + return [(thing, radius2 - distance_squared(location, thing.location)) for thing in self.things + if distance_squared(location, thing.location) <= radius2] def percept(self, agent): """By default, agent perceives things within a default radius.""" diff --git a/grid.py b/grid.py index 4400d217b..a7e032136 100644 --- a/grid.py +++ b/grid.py @@ -26,8 +26,8 @@ def distance(a, b): return math.hypot((a[0] - b[0]), (a[1] - b[1])) -def distance2(a, b): - "The square of the distance between two (x, y) points." +def distance_squared(a, b): + """The square of the distance between two (x, y) points.""" return (a[0] - b[0])**2 + (a[1] - b[1])**2 diff --git a/tests/test_grid.py b/tests/test_grid.py index 5e05a617a..928218150 100644 --- a/tests/test_grid.py +++ b/tests/test_grid.py @@ -10,8 +10,8 @@ def test_distance(): assert distance((1, 2), (5, 5)) == 5.0 -def test_distance2(): - assert distance2((1, 2), (5, 5)) == 25.0 +def test_distance_squared(): + assert distance_squared((1, 2), (5, 5)) == 25.0 def test_vector_clip():