From 7f1556b52d6d558895eeb91b82fc5ee1547295b3 Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Thu, 19 Dec 2024 22:01:51 -0800 Subject: [PATCH] Remove nearby and add units to util file --- include/aoc.hpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/include/aoc.hpp b/include/aoc.hpp index 018128f..928c6ac 100644 --- a/include/aoc.hpp +++ b/include/aoc.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include typedef long long ll; typedef unsigned long long ull; @@ -15,6 +15,13 @@ template struct Coord { this->y = y; } + static inline const std::array, 4> units = { + Coord(0, 1), + Coord(1, 0), + Coord(0, -1), + Coord(-1, 0), + }; + Coord operator-() { return {-this->x, -this->y}; } Coord &operator+=(const Coord &other) { @@ -40,27 +47,6 @@ template struct Coord { y /= other; return *this; } - - std::vector> nearby(const Coord &cMin, const Coord &cMax) { - std::vector> ret; - const T xMin = std::max(this->x - 1, cMin.x); - const T xMax = std::min(this->x + 1, cMax.x); - const T yMin = std::max(this->y - 1, cMin.y); - const T yMax = std::min(this->y + 1, cMax.y); - for (T x = xMin; x <= xMax; x++) { - for (T y = yMin; y <= yMax; y++) { - Coord xy(x, y); - if (*this != xy) { - ret.push_back(xy); - } - } - } - return ret; - } - - std::vector> nearby(const Coord &cMax) { - return this->nearby(Coord(), cMax); - } }; template