Skip to content

Commit 21bc4c1

Browse files
committed
gridutil updates
1 parent e4d0d12 commit 21bc4c1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

gridutil/coord.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
from enum import Enum, auto
2+
from collections import namedtuple
3+
from numbers import Number
24

35

4-
Coordinate = tuple[int, int]
6+
Coordinate: tuple[Number, Number] = namedtuple("Coordinate", ["x", "y"])
57

68

79
def add(a: Coordinate, b: Coordinate) -> Coordinate:
8-
xa, ya = a
9-
xb, yb = b
10-
return xa + xb, ya + yb
10+
return Coordinate(a.x + b.x, a.y + b.y)
1111

1212

1313
def sub(a: Coordinate, b: Coordinate) -> Coordinate:
14-
xa, ya = a
15-
xb, yb = b
16-
return xa - xb, ya - yb
14+
return Coordinate(a.x - b.x, a.y - b.y)
1715

1816

19-
def manhattan_dist(a: Coordinate, b: Coordinate) -> Coordinate:
17+
def mult(a: Coordinate, b: Number) -> Coordinate:
18+
return Coordinate(a.x * b, a.y * b)
19+
20+
21+
def manhattan_dist(a: Coordinate, b: Coordinate) -> Number:
2022
x, y = sub(b, a)
2123
return abs(x) + abs(y)
2224

0 commit comments

Comments
 (0)