From 21bc4c1c54ab8b0db28e95fde6500b7576f54e8e Mon Sep 17 00:00:00 2001 From: AKP Date: Mon, 18 Dec 2023 13:46:24 +0000 Subject: [PATCH] gridutil updates --- gridutil/coord.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gridutil/coord.py b/gridutil/coord.py index 2794efd..04c7b54 100644 --- a/gridutil/coord.py +++ b/gridutil/coord.py @@ -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)