Skip to content

Commit 50ea63c

Browse files
Changed Distance Functions to use Tuples as Points
1 parent e734314 commit 50ea63c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,21 @@ def turn_left(heading):
301301

302302
def distance(a, b):
303303
"The distance between two (x, y) points."
304-
return math.hypot((a.x - b.x), (a.y - b.y))
304+
ax, ay = a
305+
bx, by = b
306+
return math.hypot((ax - bx), (ay - by))
305307

306308
def distance_squared(a, b):
307309
"The distance between two (x, y) points."
308-
return (a.x - b.x)**2 + (a.y - b.y)**2
310+
ax, ay = a
311+
bx, by = b
312+
return (ax - bx)**2 + (ay - by)**2
309313

310314
def distance2(a, b):
311315
"The square of the distance between two (x, y) points."
312-
return distance_squared(a, b)
316+
ax, ay = a
317+
bx, by = b
318+
return (ax - bx)**2 + (ay - by)**2
313319

314320
def vector_clip(vector, lowest, highest):
315321
"""Return vector, except if any element is less than the corresponding

0 commit comments

Comments
 (0)