gridutil updates
This commit is contained in:
parent
e4d0d12b79
commit
21bc4c1c54
1 changed files with 10 additions and 8 deletions
|
@ -1,22 +1,24 @@
|
||||||
from enum import Enum, auto
|
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:
|
def add(a: Coordinate, b: Coordinate) -> Coordinate:
|
||||||
xa, ya = a
|
return Coordinate(a.x + b.x, a.y + b.y)
|
||||||
xb, yb = b
|
|
||||||
return xa + xb, ya + yb
|
|
||||||
|
|
||||||
|
|
||||||
def sub(a: Coordinate, b: Coordinate) -> Coordinate:
|
def sub(a: Coordinate, b: Coordinate) -> Coordinate:
|
||||||
xa, ya = a
|
return Coordinate(a.x - b.x, a.y - b.y)
|
||||||
xb, yb = b
|
|
||||||
return xa - xb, ya - yb
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
x, y = sub(b, a)
|
||||||
return abs(x) + abs(y)
|
return abs(x) + abs(y)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue