gridutil updates

This commit is contained in:
akp 2023-12-18 13:46:24 +00:00
parent e4d0d12b79
commit 21bc4c1c54
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755

View file

@ -1,22 +1,24 @@
from enum import Enum, auto
from collections import namedtuple
from numbers import Number
Coordinate = tuple[int, int]
Coordinate: tuple[Number, Number] = namedtuple("Coordinate", ["x", "y"])
def add(a: Coordinate, b: Coordinate) -> Coordinate:
xa, ya = a
xb, yb = b
return xa + xb, ya + yb
return Coordinate(a.x + b.x, a.y + b.y)
def sub(a: Coordinate, b: Coordinate) -> Coordinate:
xa, ya = a
xb, yb = b
return xa - xb, ya - yb
return Coordinate(a.x - b.x, a.y - b.y)
def manhattan_dist(a: Coordinate, b: Coordinate) -> Coordinate:
def mult(a: Coordinate, b: Number) -> Coordinate:
return Coordinate(a.x * b, a.y * b)
def manhattan_dist(a: Coordinate, b: Coordinate) -> Number:
x, y = sub(b, a)
return abs(x) + abs(y)