2022-11-06 21:12:30 -08:00
|
|
|
#include <aocpp/Coord.hpp>
|
2022-11-04 19:59:35 -07:00
|
|
|
|
2022-11-07 17:19:17 -08:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2022-11-06 21:12:30 -08:00
|
|
|
namespace aocpp {
|
2022-11-04 19:59:35 -07:00
|
|
|
|
2024-09-02 15:20:25 -07:00
|
|
|
auto Draw(std::ostream & out, std::map<Coord, std::int64_t> const& image) -> void {
|
2022-11-06 21:12:30 -08:00
|
|
|
std::int64_t minX = 0, maxX = 0, minY = 0, maxY = 0;
|
2022-11-04 19:59:35 -07:00
|
|
|
for (auto&& [k, _] : image) {
|
|
|
|
auto [x,y] = k;
|
|
|
|
minX = std::min(minX, x);
|
|
|
|
maxX = std::max(maxX, x);
|
|
|
|
minY = std::min(minY, y);
|
|
|
|
maxY = std::max(maxY, y);
|
|
|
|
}
|
2022-11-06 21:12:30 -08:00
|
|
|
for (std::int64_t y = minY; y <= maxY; y++) {
|
|
|
|
for (std::int64_t x = minX; x <= maxX; x++) {
|
2022-11-04 19:59:35 -07:00
|
|
|
auto it = image.find({x,y});
|
|
|
|
if (image.end() == it) {
|
2022-11-04 21:35:28 -07:00
|
|
|
out << "░";
|
2022-11-04 19:59:35 -07:00
|
|
|
} else switch (it->second) {
|
2022-11-04 21:35:28 -07:00
|
|
|
case 0: out << "▒"; break;
|
2022-11-04 19:59:35 -07:00
|
|
|
case 1: out << "▓"; break;
|
2022-11-04 21:35:28 -07:00
|
|
|
case 2: out << "■"; break;
|
|
|
|
case 3: out << "◆"; break;
|
|
|
|
case 4: out << "●"; break;
|
|
|
|
default: out << "★"; break;
|
2022-11-04 19:59:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
out << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Up(Coord c) -> Coord {
|
2022-11-04 21:27:08 -07:00
|
|
|
c.y -= 1;
|
2022-11-04 19:59:35 -07:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Down(Coord c) -> Coord {
|
2022-11-04 21:27:08 -07:00
|
|
|
c.y += 1;
|
2022-11-04 19:59:35 -07:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Left(Coord c) -> Coord {
|
2022-11-04 21:27:08 -07:00
|
|
|
c.x -= 1;
|
2022-11-04 19:59:35 -07:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Right(Coord c) -> Coord {
|
2022-11-04 21:27:08 -07:00
|
|
|
c.x += 1;
|
2022-11-04 19:59:35 -07:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:08 -07:00
|
|
|
auto Invert(Coord c) -> Coord {
|
|
|
|
return {c.y, c.x};
|
|
|
|
}
|
|
|
|
|
2022-11-04 19:59:35 -07:00
|
|
|
auto CW(Coord c) -> Coord {
|
2022-11-04 21:27:08 -07:00
|
|
|
c = Invert(c);
|
|
|
|
c.x = -c.x;
|
2022-11-04 19:59:35 -07:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto CCW(Coord c) -> Coord {
|
2022-11-11 17:46:56 -08:00
|
|
|
return CW(CW(CW(c)));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Turn180(Coord c) -> Coord {
|
|
|
|
return CW(CW(c));
|
2022-11-04 19:59:35 -07:00
|
|
|
}
|
|
|
|
|
2022-11-07 17:19:17 -08:00
|
|
|
auto Norm1(Coord c) -> std::int64_t {
|
|
|
|
return std::abs(c.x) + std::abs(c.y);
|
|
|
|
}
|
|
|
|
|
2023-01-23 12:46:01 -08:00
|
|
|
auto NormInf(Coord c) -> std::int64_t {
|
|
|
|
return std::max(std::abs(c.x), std::abs(c.y));
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:08 -07:00
|
|
|
auto operator+(Coord a, Coord b) -> Coord {
|
|
|
|
return {a.x + b.x, a.y + b.y};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto operator-(Coord a, Coord b) -> Coord {
|
|
|
|
return {a.x - b.x, a.y - b.y};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto operator+=(Coord & a, Coord b) -> Coord & {
|
|
|
|
a = a + b;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto operator-=(Coord & a, Coord b) -> Coord & {
|
|
|
|
a = a - b;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2023-04-08 16:54:22 -07:00
|
|
|
auto operator*(Coord a, std::int64_t b) -> Coord {
|
|
|
|
return a *= b;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto operator*(std::int64_t a, Coord b) -> Coord {
|
|
|
|
b.x *= a;
|
|
|
|
b.y *= a;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto operator*=(Coord & a, std::int64_t b) -> Coord & {
|
|
|
|
a.x *= b;
|
|
|
|
a.y *= b;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:08 -07:00
|
|
|
auto operator<<(std::ostream & out, Coord c) -> std::ostream & {
|
|
|
|
return out << "(" << c.x << "," << c.y << ")";
|
2022-11-04 19:59:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|