6#include <boat/detail/utility.hpp>
7#include <boost/pfr/ops_fields.hpp>
8#include <boost/qvm/map_vec_mat.hpp>
16 static constexpr int size = 256;
23 static int zmax(
int width,
int height)
25 auto px =
static_cast<size_t>(std::max<>({width, height,
size}));
26 auto tl =
static_cast<size_t>(std::bit_ceil(px) /
size);
27 return static_cast<int>(std::bit_width(tl)) - 1;
30 static int zoom(
int width,
int height,
double scale)
32 int lim =
zmax(width, height);
34 for (
int i = lim; i > 0; --i)
43 return pow2(
zmax(width, height) -
zoom);
46 static std::generator<tile>
all(
int width,
int height,
int zoom)
48 if (width <= 0 || height <= 0)
52 int xmax = (width - 1) / tl;
53 int ymax = (height - 1) / tl;
54 for (
int y{};
y <= ymax; ++
y)
55 for (
int x{};
x <= xmax; ++
x)
56 co_yield {.z =
zoom, .y =
y, .x =
x};
60 std::tuple<int, int, int, int>
rect(
int width,
int height)
const
62 int px =
scale(width, height,
z);
64 int x1 = std::clamp(
x * tl, 0, width);
65 int y1 = std::clamp(
y * tl, 0, height);
66 int x2 = std::clamp((
x + 1) * tl, 0, width);
67 int y2 = std::clamp((
y + 1) * tl, 0, height);
68 return {x1, y1, x2 - x1, y2 - y1};
72 auto affine(
int width,
int height)
const
74 double px =
scale(width, height,
z);
75 double tl =
size * px;
76 return boost::qvm::translation_mat(boost::qvm::vec{{
x * tl,
y * tl}}) *
77 boost::qvm::diag_mat(boost::qvm::vec{{px, px, 1.}});
84struct std::hash<
boat::tile> {
friend auto operator<=>(tile const &, tile const &)=default
static constexpr int size
Maximum tile side in pixels.
Definition tile.hpp:16
auto affine(int width, int height) const
Maps tile pixels to raster pixels.
Definition tile.hpp:72
static int scale(int width, int height, int zoom)
Raster pixels per tile pixel.
Definition tile.hpp:41
int y
Definition tile.hpp:14
friend auto hash_value(tile const &v)
Definition tile.hpp:20
std::tuple< int, int, int, int > rect(int width, int height) const
Clipped raster-pixel rectangle {x, y, width, height}.
Definition tile.hpp:60
static std::generator< tile > all(int width, int height, int zoom)
Definition tile.hpp:46
int z
Definition tile.hpp:14
static int zmax(int width, int height)
Finest zoom, with one raster pixel per tile pixel.
Definition tile.hpp:23
static int zoom(int width, int height, double scale)
Definition tile.hpp:30
int x
Definition tile.hpp:14
static auto operator()(boat::tile const &v)
Definition tile.hpp:85