10bool staggerDoShift(
const GridConfig &cfg,
int cx,
int cy) {
12 const bool odd = (major & 1) != 0;
17void offsetToCube(
int col,
int row,
int &
x,
int &
y,
int &
z) {
18 x = col - (
row - (
row & 1)) / 2;
23void cubeToOffset(
int x,
int y,
int &col,
int &row) {
25 col =
x + (
row - (
row & 1)) / 2;
48 const float pitchY = hex ? (th + cfg.
hexSideLength) * 0.5f : th * 0.5f;
50 (staggerDoShift(cfg,
cx,
cy) ? tw * 0.5f : 0.f);
53 const float pitchX = hex ? (tw + cfg.
hexSideLength) * 0.5f : tw * 0.5f;
56 (staggerDoShift(cfg,
cx,
cy) ? th * 0.5f : 0.f);
64 float px = 0.f, py = 0.f;
66 return py + cfg.
cellH;
74 const float ly = py - cfg.
originY;
77 cx = int(std::floor(lx / tw));
78 cy = int(std::floor(ly / th));
84 const float ly = py - cfg.
originY;
85 const float tw = cfg.
cellW > 0.f ? cfg.
cellW * 0.5f : 1.f;
86 const float th = cfg.
cellH > 0.f ? cfg.
cellH * 0.5f : 1.f;
87 const float a = lx / tw;
88 const float b = ly / th;
89 cx = int(std::floor((
b +
a) * 0.5f));
90 cy = int(std::floor((
b -
a) * 0.5f));
98 const int w = std::max(1, mapW);
99 const int h = std::max(1, mapH);
100 for (
int y = 0;
y <
h; ++
y) {
101 for (
int x = 0;
x <
w; ++
x) {
102 float wx = 0.f, wy = 0.f;
104 wx += cfg.
cellW * 0.5f;
105 wy += cfg.
cellH * 0.5f;
106 const float dx = wx -
px;
107 const float dy = wy - py;
108 const float d = dx * dx + dy * dy;
122 bool hexMode,
const std::function<
void(
int lx,
int ly)> &
fn) {
128 std::vector<std::pair<int, int>> solid;
129 for (
int ly = 0; ly <
h; ++ly) {
130 for (
int lx = 0; lx <
w; ++lx) {
131 bool solidCell =
true;
133 const size_t idx = size_t(ly) * size_t(
w) + size_t(lx);
134 solidCell =
idx < mask.size() && mask[
idx] != 0;
136 if (solidCell) solid.emplace_back(lx, ly);
139 if (solid.empty())
return;
142 std::vector<std::pair<int, int>> rotated;
143 rotated.reserve(solid.size());
144 int minX = 1 << 30, minY = 1 << 30;
145 for (
const auto &
c : solid) {
149 int x = 0,
y = 0,
z = 0;
150 offsetToCube(
c.first,
c.second,
x,
y,
z);
151 const int s = ((steps % 6) + 6) % 6;
152 for (
int i = 0; i <
s; ++i) {
160 cubeToOffset(
x,
y, rx, ry);
162 const int q = ((steps % 4) + 4) % 4;
166 ry =
w - 1 -
c.first;
169 rx =
w - 1 -
c.first;
170 ry =
h - 1 -
c.second;
173 rx =
h - 1 -
c.second;
180 rotated.emplace_back(rx, ry);
181 minX = std::min(minX, rx);
182 minY = std::min(minY, ry);
184 for (
const auto &
c : rotated)
fn(
c.first - minX,
c.second - minY);
188 bool hexMode,
int &outW,
int &outH) {
192 maxX = std::max(maxX, lx);
193 maxY = std::max(maxY, ly);
SettlementPipeline::Stage fn
void cellToWorld(const GridConfig &cfg, int cx, int cy, float &px, float &py)
void worldToCell(const GridConfig &cfg, float px, float py, int &cx, int &cy, int mapW, int mapH)
void foreachRotatedFootprint(int w, int h, const std::vector< uint8_t > &mask, int steps, bool hexMode, const std::function< void(int lx, int ly)> &fn)
float cellToDepthY(const GridConfig &cfg, int cx, int cy)
void rotatedFootprintSize(int w, int h, const std::vector< uint8_t > &mask, int steps, bool hexMode, int &outW, int &outH)
float cellPitchY(const GridConfig &cfg)
float cellPitchX(const GridConfig &cfg)
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.