|
|
|
@ -78,6 +78,41 @@ namespace matrix { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
template<typename MAT> |
|
|
|
|
struct viewport_t { |
|
|
|
|
Point start; |
|
|
|
|
// this is the point in the map
|
|
|
|
|
size_t x; |
|
|
|
|
size_t y; |
|
|
|
|
// this is the point inside the box, start at 0
|
|
|
|
|
size_t view_x = ~0; |
|
|
|
|
size_t view_y = ~0; |
|
|
|
|
// viewport width/height
|
|
|
|
|
size_t width; |
|
|
|
|
size_t height; |
|
|
|
|
|
|
|
|
|
viewport_t(MAT &mat, Point start, int max_x, int max_y) : |
|
|
|
|
start(start), |
|
|
|
|
x(start.x-1), |
|
|
|
|
y(start.y-1) |
|
|
|
|
{ |
|
|
|
|
width = std::min(size_t(max_x), matrix::width(mat) - start.x); |
|
|
|
|
height = std::min(size_t(max_y), matrix::height(mat) - start.y); |
|
|
|
|
fmt::println("viewport_t max_x, max_y {},{} vs matrix {},{}, x={}, y={}", |
|
|
|
|
max_x, max_y, matrix::width(mat), matrix::height(mat), x, y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool next() { |
|
|
|
|
y = next_y(x, y); |
|
|
|
|
x = next_x(x, width); |
|
|
|
|
view_x = next_x(view_x, width); |
|
|
|
|
view_y = next_y(view_x, view_y); |
|
|
|
|
return at_end(y, height); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
using viewport = viewport_t<Matrix>; |
|
|
|
|
|
|
|
|
|
using each_cell = each_cell_t<Matrix>; |
|
|
|
|
|
|
|
|
|
template<typename MAT> |
|
|
|
|