1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
struct cell { unsigned x = 0; unsigned y = 0; };
static constexpr int __helix_radius = 3; static constexpr int __helix_size = (__helix_radius * 2 + 1) * (__helix_radius * 2 + 1); static cell __cell_helix[__helix_size];
static int _helix(int x, int y) { int t = std::max(std::abs(x), std::abs(y)); int u = t + t; int v = u - 1;
v = v * v + u; if( x == -t ) v += u + t - y; else if( y == -t ) v += 3 * u + x - t; else if( y == t ) v += t - x; else v += y - t;
return v - 1; }
static bool _init_helix() { for(int y = -1 * __helix_radius; y <= __helix_radius; ++y) { for(int x = -1 * __helix_radius; x <= __helix_radius; ++x) { cell& cpt = __cell_helix[_helix(x, y)]; cpt.x = x; cpt.y = y; } }
return true; }
static bool __call_init_helix = _init_helix();
|