From e67df73b3a3e0d28d60ff2045cc4a34a30d1bf60 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Mon, 23 Jan 2023 14:46:01 -0600 Subject: [PATCH] new coord stuff from 09 --- lib/include/aocpp/Coord.hpp | 8 ++++++++ lib/src/Coord.cpp | 4 ++++ 2 files changed, 12 insertions(+) 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}; }