diff --git a/lib/include/aocpp/Coord.hpp b/lib/include/aocpp/Coord.hpp index 170b768..8782f3d 100644 --- a/lib/include/aocpp/Coord.hpp +++ b/lib/include/aocpp/Coord.hpp @@ -41,8 +41,16 @@ auto CCW(Coord) -> Coord; auto Turn180(Coord) -> Coord; +/// @brief Computes the "1 norm" of a coordinate as a vector +/// @param vector +/// @return Sum of magnitudes of components auto Norm1(Coord) -> std::int64_t; +/// @brief Computes the "infinity norm" of a coordinate as a vector +/// @param vector +/// @return Magnitude of the largest component +auto NormInf(Coord) -> std::int64_t; + /// Add two coordinates pairwise auto operator+(Coord, Coord) -> Coord; diff --git a/lib/src/Coord.cpp b/lib/src/Coord.cpp index 7800f5b..33a4027 100644 --- a/lib/src/Coord.cpp +++ b/lib/src/Coord.cpp @@ -73,6 +73,10 @@ auto Norm1(Coord c) -> std::int64_t { return std::abs(c.x) + std::abs(c.y); } +auto NormInf(Coord c) -> std::int64_t { + return std::max(std::abs(c.x), std::abs(c.y)); +} + auto operator+(Coord a, Coord b) -> Coord { return {a.x + b.x, a.y + b.y}; }