#ifndef INTCODE_COORD_HPP_ #define INTCODE_COORD_HPP_ #include #include #include #include #include namespace intcode { /// Cartesian coordinate /// /// Coordinate where y grows down and x grows right struct Coord { std::int64_t x, y; auto operator<=>(const Coord&) const = default; }; auto Draw(std::ostream & out, std::map image) -> void; /// Move one unit up auto Up(Coord) -> Coord; /// Move one unit down auto Down(Coord) -> Coord; /// Move one unit left auto Left(Coord) -> Coord; /// Move one unit right auto Right(Coord) -> Coord; /// Mirror coordinates about y=x line auto Invert(Coord) -> Coord; /// Rotate clockwise auto CW(Coord) -> Coord; /// Rotate counter-clockwise auto CCW(Coord) -> Coord; /// Add two coordinates pairwise auto operator+(Coord, Coord) -> Coord; /// Subtract two coordinates pairwise auto operator-(Coord, Coord) -> Coord; /// Compound assignment addition of coordinates auto operator+=(Coord &, Coord) -> Coord &; /// Compound assignment subtraction of coordinates auto operator-=(Coord &, Coord) -> Coord &; /// Write a coordinate to a string "(x,y)" auto operator<<(std::ostream &, Coord) -> std::ostream &; } // namespace template<> struct std::hash { auto operator()(intcode::Coord const& c) const noexcept -> std::size_t { std::hash h; return h(c.x) ^ h(c.y); } }; #endif