You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
2.4 KiB
127 lines
2.4 KiB
#pragma once
|
|
#include <vector>
|
|
#include <queue>
|
|
#include <string>
|
|
#include <array>
|
|
#include <fmt/core.h>
|
|
#include "point.hpp"
|
|
|
|
using fmt::println;
|
|
|
|
namespace matrix {
|
|
using std::vector, std::queue, std::array;
|
|
|
|
typedef vector<int> Row;
|
|
typedef vector<Row> Matrix;
|
|
|
|
struct each_cell {
|
|
size_t x = ~0;
|
|
size_t y = ~0;
|
|
size_t width = 0;
|
|
size_t height = 0;
|
|
|
|
each_cell(Matrix &mat);
|
|
bool next();
|
|
};
|
|
|
|
struct each_row {
|
|
Matrix &$mat;
|
|
size_t x = ~0;
|
|
size_t y = ~0;
|
|
size_t width = 0;
|
|
size_t height = 0;
|
|
bool row = false;
|
|
|
|
each_row(Matrix &mat);
|
|
bool next();
|
|
};
|
|
|
|
struct in_box {
|
|
size_t x = 0; // these are set in constructor
|
|
size_t y = 0; // again, no fancy ~ trick needed
|
|
size_t left = 0;
|
|
size_t top = 0;
|
|
size_t right = 0;
|
|
size_t bottom = 0;
|
|
|
|
in_box(Matrix &mat, size_t x, size_t y, size_t size);
|
|
bool next();
|
|
void dump();
|
|
};
|
|
|
|
struct compass {
|
|
size_t x = 0; // these are set in constructor
|
|
size_t y = 0; // again, no fancy ~ trick needed
|
|
array<int, 4> x_dirs{0, 1, 0, -1};
|
|
array<int, 4> y_dirs{-1, 0, 1, 0};
|
|
size_t max_dirs=0;
|
|
size_t dir = ~0;
|
|
|
|
compass(Matrix &mat, size_t x, size_t y);
|
|
bool next();
|
|
};
|
|
|
|
/*
|
|
* Just a quick thing to reset a matrix to a value.
|
|
*/
|
|
inline void assign(Matrix &out, int new_value) {
|
|
for(auto &row : out) {
|
|
row.assign(row.size(), new_value);
|
|
}
|
|
}
|
|
|
|
inline bool inbounds(Matrix &mat, size_t x, size_t y) {
|
|
// since Point.x and Point.y are size_t any negatives are massive
|
|
bool res = (y < mat.size()) && (x < mat[0].size());
|
|
return res;
|
|
}
|
|
|
|
void dump(const std::string &msg, Matrix &map, int show_x=-1, int show_y=-1);
|
|
|
|
struct flood {
|
|
Matrix &mat;
|
|
Point start;
|
|
int old_val;
|
|
int new_val;
|
|
queue<Point> q;
|
|
Point current_loc;
|
|
int x;
|
|
int y;
|
|
matrix::compass dirs;
|
|
|
|
flood(Matrix &mat, Point start, int old_val, int new_val);
|
|
bool next();
|
|
bool next_working();
|
|
};
|
|
|
|
struct line {
|
|
int x;
|
|
int y;
|
|
int x1;
|
|
int y1;
|
|
int sx;
|
|
int sy;
|
|
int dx;
|
|
int dy;
|
|
int error;
|
|
|
|
line(Point start, Point end);
|
|
bool next();
|
|
};
|
|
|
|
struct circle {
|
|
Point center;
|
|
int radius = 0;
|
|
int xi = 0;
|
|
int yi = 0;
|
|
int m = 0;
|
|
int step = 0;
|
|
int x0;
|
|
int x1;
|
|
int y;
|
|
|
|
circle(Point center, int radius);
|
|
void update();
|
|
bool next();
|
|
};
|
|
}
|
|
|