day05: Coordinate() learned a new trick :)

This commit is contained in:
Stefan Harmuth 2021-12-05 07:16:09 +01:00
parent da4b6567a3
commit bf0b19a1b9

View File

@ -1,7 +1,6 @@
from aoc import AOCDay
from coordinate import Coordinate
from grid import Grid
from tools import compare
from typing import Any
@ -13,9 +12,8 @@ def buildLineGrid(lines: list[list[str]], diagonals: bool = False) -> Grid:
if not diagonals and start.x != end.x and start.y != end.y:
continue
diff = end - start
for x in range(max(abs(diff.x), abs(diff.y)) + 1):
grid.add(Coordinate(start.x + compare(diff.x, 0) * x, start.y + compare(diff.y, 0) * x))
for c in start.getLineTo(end):
grid.add(c)
return grid