72 lines
1.4 KiB
C++
72 lines
1.4 KiB
C++
#ifndef INTCODE_COORD_HPP_
|
|
#define INTCODE_COORD_HPP_
|
|
|
|
#include <functional>
|
|
#include <map>
|
|
#include <ostream>
|
|
#include <tuple>
|
|
|
|
#include <intcode/Machine.hpp>
|
|
|
|
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<Coord, ValueType> 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<intcode::Coord>
|
|
{
|
|
auto operator()(intcode::Coord const& c) const noexcept -> std::size_t {
|
|
std::hash<std::int64_t> h;
|
|
return h(c.x) ^ h(c.y);
|
|
}
|
|
};
|
|
|
|
#endif
|