jazz up Coord
This commit is contained in:
71
lib/include/intcode/Coord.hpp
Normal file
71
lib/include/intcode/Coord.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#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
|
@@ -1,27 +0,0 @@
|
||||
#ifndef INTCODE_GRID_HPP_
|
||||
#define INTCODE_GRID_HPP_
|
||||
|
||||
#include <ostream>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
#include <intcode/Machine.hpp>
|
||||
|
||||
namespace intcode {
|
||||
|
||||
using Coord = std::pair<ValueType, ValueType>;
|
||||
|
||||
auto Draw(std::ostream & out, std::map<Coord, ValueType> image) -> void;
|
||||
|
||||
auto Up(Coord) -> Coord;
|
||||
auto Down(Coord) -> Coord;
|
||||
auto Left(Coord) -> Coord;
|
||||
auto Right(Coord) -> Coord;
|
||||
auto CW(Coord) -> Coord;
|
||||
auto CCW(Coord) -> Coord;
|
||||
auto Add(Coord, Coord) -> Coord;
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user