2018-04-09 15:40:38 +00:00
|
|
|
namespace gp {
|
|
|
|
bool on;
|
2018-04-03 21:25:43 +00:00
|
|
|
loc param(1, 0);
|
|
|
|
|
|
|
|
hyperpoint next;
|
|
|
|
ld scale;
|
|
|
|
ld alpha;
|
|
|
|
int area;
|
|
|
|
|
|
|
|
loc operator+(loc e1, loc e2) {
|
|
|
|
return make_pair(e1.first+e2.first, e1.second+e2.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
loc operator-(loc e1, loc e2) {
|
|
|
|
return make_pair(e1.first-e2.first, e1.second-e2.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
loc operator*(loc e1, loc e2) {
|
|
|
|
return make_pair(e1.first*e2.first-e1.second*e2.second,
|
|
|
|
e1.first*e2.second + e2.first*e1.second + e1.second*e2.second);
|
|
|
|
}
|
|
|
|
|
2018-04-09 15:40:38 +00:00
|
|
|
struct goldberg_mapping_t {
|
2018-04-11 13:55:43 +00:00
|
|
|
cellwalker cw;
|
2018-04-03 21:25:43 +00:00
|
|
|
char rdir;
|
|
|
|
};
|
|
|
|
|
|
|
|
loc eudir(int d) {
|
|
|
|
d %= 6; if (d < 0) d += 6;
|
|
|
|
switch(d) {
|
|
|
|
case 0: return make_pair(1, 0);
|
|
|
|
case 1: return make_pair(0, 1);
|
|
|
|
case 2: return make_pair(-1, 1);
|
|
|
|
case 3: return make_pair(-1, 0);
|
|
|
|
case 4: return make_pair(0, -1);
|
|
|
|
case 5: return make_pair(1, -1);
|
|
|
|
default: return make_pair(0, 0);
|
|
|
|
}
|
|
|
|
}
|
2018-04-04 16:00:40 +00:00
|
|
|
|
2018-04-05 22:40:53 +00:00
|
|
|
int get_code(const local_info& li) {
|
|
|
|
return
|
|
|
|
((li.relative.first & 15) << 0) +
|
|
|
|
((li.relative.second & 15) << 4) +
|
|
|
|
((fix6(li.total_dir)) << 8) +
|
|
|
|
((li.last_dir & 15) << 12);
|
2018-04-04 16:00:40 +00:00
|
|
|
}
|
2018-04-05 22:40:53 +00:00
|
|
|
|
|
|
|
local_info get_local_info(cell *c) {
|
|
|
|
local_info li;
|
|
|
|
if(c == c->master->c7) {
|
|
|
|
li.relative = loc(0,0);
|
|
|
|
li.first_dir = -1;
|
|
|
|
li.last_dir = -1;
|
|
|
|
li.total_dir = -1;
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
2018-04-05 22:40:53 +00:00
|
|
|
else {
|
|
|
|
vector<int> dirs;
|
|
|
|
while(c != c->master->c7) {
|
|
|
|
dirs.push_back(c->spin(0));
|
|
|
|
c = c->mov[0];
|
|
|
|
}
|
|
|
|
li.first_dir = dirs[0];
|
|
|
|
li.last_dir = dirs.back();
|
|
|
|
|
|
|
|
loc at(0,0);
|
|
|
|
int dir = 0;
|
2018-04-03 21:25:43 +00:00
|
|
|
at = at + eudir(dir);
|
2018-04-05 22:40:53 +00:00
|
|
|
dirs.pop_back();
|
|
|
|
while(dirs.size()) {
|
|
|
|
dir += dirs.back() + 3;
|
|
|
|
dirs.pop_back();
|
|
|
|
at = at + eudir(dir);
|
|
|
|
}
|
|
|
|
li.relative = at;
|
|
|
|
li.total_dir = dir + 3;
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
2018-04-05 22:40:53 +00:00
|
|
|
return li;
|
|
|
|
}
|
|
|
|
|
|
|
|
int last_dir(cell *c) {
|
|
|
|
return get_local_info(c).last_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
loc get_coord(cell *c) {
|
|
|
|
return get_local_info(c).relative;
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 15:59:24 +00:00
|
|
|
int pseudohept_val(cell *c) {
|
2018-04-03 21:25:43 +00:00
|
|
|
loc v = get_coord(c);
|
2018-04-04 15:59:24 +00:00
|
|
|
return (v.first - v.second + MODFIXER)%3;
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 13:55:43 +00:00
|
|
|
// mapping of the local equilateral triangle
|
|
|
|
// goldberg_map[y][x].cw is the cellwalker in this triangle at position (x,y)
|
|
|
|
// facing local direction 0
|
|
|
|
|
2018-04-10 22:53:22 +00:00
|
|
|
goldberg_mapping_t goldberg_map[32][32];
|
2018-04-09 15:40:38 +00:00
|
|
|
void clear_mapping() {
|
2018-04-10 22:53:22 +00:00
|
|
|
for(int y=0; y<32; y++) for(int x=0; x<32; x++) {
|
2018-04-11 13:55:43 +00:00
|
|
|
goldberg_map[y][x].cw.c = NULL;
|
2018-04-09 15:40:38 +00:00
|
|
|
goldberg_map[y][x].rdir = -1;
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 15:40:38 +00:00
|
|
|
goldberg_mapping_t& get_mapping(loc c) {
|
2018-04-10 22:53:22 +00:00
|
|
|
return goldberg_map[c.second&31][c.first&31];
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *disp(loc at) {
|
|
|
|
static char bufs[16][16];
|
|
|
|
static int bufid;
|
|
|
|
bufid++; bufid %= 16;
|
|
|
|
snprintf(bufs[bufid], 16, "[%d,%d]", at.first, at.second);
|
|
|
|
return bufs[bufid];
|
|
|
|
}
|
|
|
|
|
2018-04-11 13:55:43 +00:00
|
|
|
const char *dcw(cellwalker cw) {
|
|
|
|
static char bufs[16][32];
|
|
|
|
static int bufid;
|
|
|
|
bufid++; bufid %= 16;
|
|
|
|
snprintf(bufs[bufid], 32, "[%p/%d:%d:%d]", cw.c, cw.c?cw.c->type:-1, cw.spin, cw.mirrored);
|
|
|
|
return bufs[bufid];
|
|
|
|
}
|
|
|
|
|
2018-04-03 21:25:43 +00:00
|
|
|
int spawn;
|
|
|
|
|
|
|
|
#define WHD(x) // x
|
|
|
|
|
|
|
|
void conn1(loc at, int dir, int dir1) {
|
2018-04-09 15:40:38 +00:00
|
|
|
auto& wc = get_mapping(at);
|
|
|
|
auto& wc1 = get_mapping(at + eudir(dir));
|
2018-04-11 13:55:43 +00:00
|
|
|
int cdir = (wc.cw + dir).spin;
|
|
|
|
WHD( printf(" connection %s/%d %s ", disp(at), dir, dcw(wc.cw+dir)); )
|
|
|
|
if(!wc1.cw.c) {
|
|
|
|
wc1.cw.c = wc.cw.c->mov[cdir];
|
|
|
|
if(wc1.cw.c) {
|
2018-04-03 21:25:43 +00:00
|
|
|
// wc1.c/wc.c->spin(cdir) == dir1
|
2018-04-11 13:55:43 +00:00
|
|
|
wc1.cw = (wc.cw + dir + wstep - dir1);
|
2018-04-03 21:25:43 +00:00
|
|
|
WHD( printf("(pulled) "); )
|
|
|
|
}
|
2018-04-11 13:55:43 +00:00
|
|
|
if(!wc1.cw.c) {
|
|
|
|
wc1.cw.c = newCell(6, wc.cw.c->master);
|
2018-04-03 21:25:43 +00:00
|
|
|
spawn++;
|
|
|
|
// 0 for wc1.c should be dir1
|
2018-04-11 13:55:43 +00:00
|
|
|
wc1.cw.mirrored = wc.cw.mirrored;
|
|
|
|
wc1.cw.spin = fix6(wc.cw.mirrored ? dir1 : -dir1);
|
2018-04-03 21:25:43 +00:00
|
|
|
WHD( printf("(created) "); )
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 13:55:43 +00:00
|
|
|
int cdir1 = (wc1.cw + dir1).spin;
|
|
|
|
WHD( printf("%s ", dcw(wc1.cw+dir1)); )
|
|
|
|
if(wc.cw.c->mov[cdir] && wc.cw.c->mov[cdir] != wc1.cw.c) {
|
|
|
|
WHD( printf("FAIL: %p\n", wc.cw.c->mov[cdir]); exit(1); )
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
2018-04-11 13:55:43 +00:00
|
|
|
if(wc.cw.c->mov[cdir]) {
|
|
|
|
if(wc.cw.c->spin(cdir) != cdir1) {
|
|
|
|
printf("warning: wrong spin: %d vs %d\n", wc.cw.c->spin(cdir), cdir1);
|
2018-04-03 21:25:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 13:55:43 +00:00
|
|
|
WHD(printf("ok\n"); )
|
|
|
|
wc.cw.c->mov[cdir] = wc1.cw.c;
|
|
|
|
tsetspin(wc.cw.c->spintable, cdir, cdir1 + (wc.cw.mirrored != wc1.cw.mirrored ? 8 : 0));
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void conn(loc at, int dir) {
|
|
|
|
conn1(at, fix6(dir), fix6(dir+3));
|
|
|
|
conn1(at + eudir(dir), fix6(dir+3), fix6(dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
void extend_map(cell *c, int d) {
|
|
|
|
WHD( printf("EXTEND %p %d\n", c, d); )
|
|
|
|
if(c->master->c7 != c) {
|
|
|
|
while(c->master->c7 != c) {
|
2018-04-11 13:55:43 +00:00
|
|
|
WHD( printf("%p direction 0 corresponds to %p direction %d\n", c, c->mov[0], c->spin(0)); )
|
2018-04-03 21:25:43 +00:00
|
|
|
d = c->spin(0);
|
|
|
|
c = c->mov[0];
|
|
|
|
}
|
|
|
|
// c move 0 equals c' move spin(0)
|
|
|
|
extend_map(c, d);
|
|
|
|
extend_map(c, fixdir(d-1, c));
|
|
|
|
extend_map(c, fixdir(d+1, c));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-09 15:40:38 +00:00
|
|
|
clear_mapping();
|
2018-04-03 21:25:43 +00:00
|
|
|
|
|
|
|
// we generate a local map from an Euclidean grid to the
|
|
|
|
// hyperbolic grid we build.
|
|
|
|
|
|
|
|
// we fill the equilateral triangle with the following vertices:
|
|
|
|
|
|
|
|
loc vc[3];
|
|
|
|
vc[0] = loc(0,0);
|
|
|
|
vc[1] = param;
|
|
|
|
vc[2] = param * loc(0,1);
|
|
|
|
|
2018-04-09 15:40:38 +00:00
|
|
|
// get_mapping(loc) gives our local map. We set the vertices first
|
2018-04-03 21:25:43 +00:00
|
|
|
{
|
|
|
|
auto h = c->master;
|
2018-04-09 15:40:38 +00:00
|
|
|
auto& ac0 = get_mapping(vc[0]);
|
2018-04-11 13:55:43 +00:00
|
|
|
ac0.cw = cellwalker(h->c7, d);
|
|
|
|
WHD( printf("%s : %s\n", disp(vc[0]), dcw(ac0.cw)); )
|
2018-04-03 21:25:43 +00:00
|
|
|
|
2018-04-11 13:55:43 +00:00
|
|
|
// 3 ~ h->spin(d)
|
2018-04-09 15:40:38 +00:00
|
|
|
auto& ac1 = get_mapping(vc[1]);
|
2018-04-11 15:03:29 +00:00
|
|
|
cell *c0 = createStep(h, d)->c7;
|
|
|
|
ac1.cw = cellwalker(c0, h->spin(d) - (h->mirror(d) ? -3 : 3), h->mirror(d));
|
2018-04-11 13:55:43 +00:00
|
|
|
WHD( printf("%s : %s\n", disp(vc[1]), dcw(ac1.cw)); )
|
2018-04-03 21:25:43 +00:00
|
|
|
|
|
|
|
|
2018-04-09 15:40:38 +00:00
|
|
|
auto& ac2 = get_mapping(vc[2]);
|
2018-04-11 13:55:43 +00:00
|
|
|
int d1 = (d+1)%S7;
|
2018-04-11 15:03:29 +00:00
|
|
|
cell *c1 = createStep(h, d1)->c7;
|
|
|
|
ac2.cw = cellwalker(c1, h->spin(d1) - (h->mirror(d1) ? -4 : 4), h->mirror(d1));
|
2018-04-11 13:55:43 +00:00
|
|
|
WHD( printf("%s : %s\n", disp(vc[2]), dcw(ac2.cw)); )
|
2018-04-11 15:03:29 +00:00
|
|
|
// 4 ~ h->spin(d1)
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// then we set the edges of our big equilateral triangle (in a symmetric way)
|
|
|
|
for(int i=0; i<3; i++) {
|
|
|
|
loc start = vc[i];
|
|
|
|
loc end = vc[(i+1)%3];
|
|
|
|
WHD( printf("from %s to %s\n", disp(start), disp(end)); )
|
|
|
|
loc rel = param;
|
|
|
|
auto build = [&] (loc& at, int dx, bool forward) {
|
|
|
|
int dx1 = dx + 2*i;
|
2018-04-11 13:55:43 +00:00
|
|
|
WHD( printf("%s %d .. %s %d\n", disp(at), dx1, disp(at + eudir(dx1)), fix6(dx1+3)); )
|
2018-04-03 21:25:43 +00:00
|
|
|
conn(at, dx1);
|
2018-04-09 15:40:38 +00:00
|
|
|
if(forward) get_mapping(at).rdir = fix6(dx1);
|
|
|
|
else get_mapping(at+eudir(dx1)).rdir = fix6(dx1+3);
|
2018-04-03 21:25:43 +00:00
|
|
|
at = at + eudir(dx1);
|
|
|
|
};
|
2018-04-13 12:50:40 +00:00
|
|
|
while(rel.first >= 2 && rel.first >= 2 - rel.second) {
|
2018-04-03 21:25:43 +00:00
|
|
|
build(start, 0, true);
|
|
|
|
build(end, 3, false);
|
|
|
|
rel.first -= 2;
|
|
|
|
}
|
|
|
|
while(rel.second >= 2) {
|
|
|
|
build(start, 1, true);
|
|
|
|
build(end, 4, false);
|
|
|
|
rel.second -= 2;
|
|
|
|
}
|
2018-04-13 12:50:40 +00:00
|
|
|
while(rel.second <= -2) {
|
|
|
|
build(start, 5, true);
|
|
|
|
build(end, 2, false);
|
|
|
|
rel.second += 2;
|
|
|
|
rel.first -= 2;
|
|
|
|
}
|
|
|
|
while((rel.first>0 && rel.second > 0) | (rel.first > 1 && rel.second < 0)) {
|
2018-04-03 21:25:43 +00:00
|
|
|
build(start, 0, true);
|
|
|
|
build(end, 3, false);
|
|
|
|
rel.first -= 2;
|
|
|
|
}
|
|
|
|
for(int k=0; k<6; k++)
|
|
|
|
if(start + eudir(k+2*i) == end)
|
|
|
|
build(start, k, true);
|
|
|
|
if(start != end) { printf("assertion failed: start %s == end %s\n", disp(start), disp(end)); exit(1); }
|
|
|
|
}
|
|
|
|
|
|
|
|
// now we can fill the interior of our big equilateral triangle
|
|
|
|
loc at = vc[0];
|
|
|
|
while(true) {
|
2018-04-09 15:40:38 +00:00
|
|
|
auto& wc = get_mapping(at);
|
2018-04-03 21:25:43 +00:00
|
|
|
int dx = wc.rdir;
|
|
|
|
auto at1 = at + eudir(dx);
|
2018-04-09 15:40:38 +00:00
|
|
|
auto& wc1 = get_mapping(at1);
|
2018-04-03 21:25:43 +00:00
|
|
|
WHD( printf("%s (%d) %s (%d)\n", disp(at), dx, disp(at1), wc1.rdir); )
|
|
|
|
int df = wc1.rdir - dx;
|
|
|
|
if(df < 0) df += 6;
|
|
|
|
if(df == 3) break;
|
|
|
|
switch(df) {
|
|
|
|
case 0:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
at = at1;
|
|
|
|
continue;
|
|
|
|
case 2: {
|
|
|
|
conn(at, dx+1);
|
|
|
|
wc.rdir = (dx+1) % 6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1: {
|
|
|
|
auto at2 = at + eudir(dx+1);
|
2018-04-09 15:40:38 +00:00
|
|
|
auto& wc2 = get_mapping(at2);
|
2018-04-11 13:55:43 +00:00
|
|
|
if(wc2.cw.c) { at = at1; continue; }
|
2018-04-03 21:25:43 +00:00
|
|
|
wc.rdir = (dx+1) % 6;
|
|
|
|
conn(at, (dx+1) % 6);
|
|
|
|
conn(at1, (dx+2) % 6);
|
|
|
|
conn(at2, (dx+0) % 6);
|
|
|
|
wc1.rdir = -1;
|
|
|
|
wc2.rdir = dx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
printf("case unhandled %d\n", df);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHD( printf("DONE\n\n"); )
|
|
|
|
}
|
|
|
|
|
2018-04-03 23:19:21 +00:00
|
|
|
hyperpoint loctoh_ort(loc at) {
|
|
|
|
return hpxyz(at.first, at.second, 1);
|
|
|
|
}
|
2018-04-05 22:40:53 +00:00
|
|
|
|
|
|
|
hyperpoint corner_coords[7] = {
|
|
|
|
hpxyz(2, -1, 0),
|
|
|
|
hpxyz(1, 1, 0),
|
|
|
|
hpxyz(-1, 2, 0),
|
|
|
|
hpxyz(-2, 1, 0),
|
|
|
|
hpxyz(-1, -1, 0),
|
|
|
|
hpxyz(1, -2, 0),
|
|
|
|
hpxyz(0, 0, 0) // center, not a corner
|
|
|
|
};
|
|
|
|
|
|
|
|
hyperpoint atz(const transmatrix& T, const transmatrix& corners, loc at, int cornerid = 6, ld cf = 3) {
|
2018-04-03 23:19:21 +00:00
|
|
|
int sp = 0;
|
|
|
|
again:
|
2018-04-05 22:40:53 +00:00
|
|
|
auto corner = corners * hyperpoint_vec::operator+ (loctoh_ort(at), hyperpoint_vec::operator/ (corner_coords[cornerid], cf));
|
2018-04-03 23:19:21 +00:00
|
|
|
if(corner[1] < -1e-6 || corner[2] < -1e-6) {
|
|
|
|
at = at * eudir(1);
|
2018-04-05 22:40:53 +00:00
|
|
|
if(cornerid < 6) cornerid = (1 + cornerid) % 6;
|
2018-04-03 23:19:21 +00:00
|
|
|
sp++;
|
|
|
|
goto again;
|
|
|
|
}
|
2018-04-06 08:30:06 +00:00
|
|
|
if(sp>3) sp -= 6;
|
2018-04-03 23:19:21 +00:00
|
|
|
|
|
|
|
return normalize(spin(2*M_PI*sp/S7) * T * corner);
|
|
|
|
}
|
|
|
|
|
|
|
|
transmatrix Tf[8][32][32][6];
|
|
|
|
|
2018-04-05 22:40:53 +00:00
|
|
|
transmatrix corners;
|
|
|
|
|
|
|
|
transmatrix dir_matrix(int i) {
|
|
|
|
cell cc; cc.type = S7;
|
|
|
|
return spin(-alpha) * build_matrix(
|
|
|
|
C0,
|
|
|
|
ddspin(&cc, i) * xpush(tessf) * C0,
|
|
|
|
ddspin(&cc, i+1) * xpush(tessf) * C0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-03 23:19:21 +00:00
|
|
|
void prepare_matrices() {
|
2018-04-05 22:40:53 +00:00
|
|
|
corners = inverse(build_matrix(
|
2018-04-03 23:19:21 +00:00
|
|
|
loctoh_ort(loc(0,0)),
|
|
|
|
loctoh_ort(param),
|
|
|
|
loctoh_ort(param * loc(0,1))
|
|
|
|
));
|
|
|
|
for(int i=0; i<S7; i++) {
|
2018-04-05 22:40:53 +00:00
|
|
|
transmatrix T = dir_matrix(i);
|
2018-04-03 23:19:21 +00:00
|
|
|
for(int x=-10; x<10; x++)
|
|
|
|
for(int y=-10; y<10; y++)
|
|
|
|
for(int d=0; d<6; d++) {
|
|
|
|
loc at = loc(x, y);
|
|
|
|
|
2018-04-05 22:40:53 +00:00
|
|
|
hyperpoint h = atz(T, corners, at, 6);
|
|
|
|
hyperpoint hl = atz(T, corners, at + eudir(d), 6);
|
2018-04-03 23:19:21 +00:00
|
|
|
Tf[i][x&31][y&31][d] = rgpushxto0(h) * rspintox(gpushxto0(h) * hl) * spin(M_PI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-05 22:40:53 +00:00
|
|
|
|
|
|
|
hyperpoint get_corner_position(cell *c, int cid, ld cf = 3) {
|
|
|
|
auto li = get_local_info(c);
|
|
|
|
int i = li.last_dir;
|
|
|
|
if(i == -1)
|
|
|
|
return atz(dir_matrix(cid), corners, li.relative, 0, cf);
|
|
|
|
else {
|
|
|
|
auto& cellmatrix = Tf[i][li.relative.first&31][li.relative.second&31][fix6(li.total_dir)];
|
|
|
|
return inverse(cellmatrix) * atz(dir_matrix(i), corners, li.relative, fix6(cid + li.total_dir), cf);
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 23:19:21 +00:00
|
|
|
|
2018-04-10 15:06:04 +00:00
|
|
|
map<pair<int, int>, loc> center_locs;
|
|
|
|
|
2018-04-03 21:25:43 +00:00
|
|
|
void compute_geometry() {
|
2018-04-10 15:06:04 +00:00
|
|
|
center_locs.clear();
|
2018-04-09 15:40:38 +00:00
|
|
|
if(on) {
|
2018-04-03 21:25:43 +00:00
|
|
|
int x = param.first;
|
|
|
|
int y = param.second;
|
|
|
|
area = ((2*x+y) * (2*x+y) + y*y*3) / 4;
|
|
|
|
next = hpxyz(x+y/2., -y * sqrt(3) / 2, 0);
|
|
|
|
scale = 1 / hypot2(next);
|
|
|
|
crossf *= scale;
|
|
|
|
hepvdist *= scale;
|
|
|
|
rhexf *= scale;
|
|
|
|
// spin = spintox(next);
|
|
|
|
// ispin = rspintox(next);
|
|
|
|
alpha = -atan2(next[1], next[0]);
|
|
|
|
base_distlimit = (base_distlimit + log(scale) / log(2.618)) / scale;
|
2018-04-03 22:14:28 +00:00
|
|
|
if(base_distlimit > 30)
|
|
|
|
base_distlimit = 30;
|
2018-04-03 23:19:21 +00:00
|
|
|
prepare_matrices();
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
scale = 1;
|
|
|
|
alpha = 0;
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 12:50:40 +00:00
|
|
|
|
|
|
|
loc config;
|
|
|
|
|
|
|
|
loc internal_representation(loc v) {
|
|
|
|
int& x = v.first, &y = v.second;
|
|
|
|
while(x < 0 || y < 0 || (x == 0 && y > 0))
|
|
|
|
v = v * loc(0, 1);
|
|
|
|
if(x > 8) x = 8;
|
|
|
|
if(y > 8) y = 8;
|
|
|
|
if(y > x) v = v * loc(1, -1);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
loc human_representation(loc v) {
|
|
|
|
int& x = v.first, &y = v.second;
|
|
|
|
while(x < 0 || y < 0 || (x == 0 && y > 0))
|
|
|
|
v = v * loc(0, 1);
|
|
|
|
return v;
|
|
|
|
}
|
2018-04-03 21:25:43 +00:00
|
|
|
|
|
|
|
string operation_name() {
|
2018-04-09 15:40:38 +00:00
|
|
|
if(!gp::on) {
|
2018-04-03 21:25:43 +00:00
|
|
|
if(nonbitrunc) return XLAT("OFF");
|
|
|
|
else return XLAT("bitruncated");
|
|
|
|
}
|
|
|
|
else if(param == loc(1, 0))
|
|
|
|
return XLAT("OFF");
|
|
|
|
else if(param == loc(1, 1))
|
|
|
|
return XLAT("bitruncated");
|
|
|
|
else if(param == loc(2, 0))
|
|
|
|
return XLAT("chamfered");
|
|
|
|
else if(param == loc(3, 0))
|
|
|
|
return XLAT("2x bitruncated");
|
2018-04-13 12:50:40 +00:00
|
|
|
else {
|
|
|
|
auto p = human_representation(param);
|
|
|
|
return "GP(" + its(p.first) + "," + its(p.second) + ")";
|
|
|
|
}
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 12:50:40 +00:00
|
|
|
void whirl_set(loc xy, bool texture_remap) {
|
2018-04-18 18:53:37 +00:00
|
|
|
#if CAP_TEXTURE
|
2018-04-10 03:12:40 +00:00
|
|
|
auto old_tstate = texture::config.tstate;
|
|
|
|
auto old_tstate_max = texture::config.tstate_max;
|
2018-04-18 18:53:37 +00:00
|
|
|
#endif
|
2018-04-13 12:50:40 +00:00
|
|
|
xy = internal_representation(xy);
|
|
|
|
if(xy.second && elliptic) {
|
|
|
|
if(xy.second==xy.first)
|
2018-04-11 13:55:43 +00:00
|
|
|
addMessage("GP(x,x) not implemented yet for elliptic geometry");
|
|
|
|
else
|
|
|
|
addMessage("This does not work in elliptic geometry");
|
2018-04-13 12:50:40 +00:00
|
|
|
xy.second = 0;
|
2018-04-11 13:55:43 +00:00
|
|
|
}
|
2018-04-13 12:50:40 +00:00
|
|
|
config = human_representation(xy);
|
2018-04-03 21:25:43 +00:00
|
|
|
auto g = screens;
|
2018-04-13 12:50:40 +00:00
|
|
|
if(xy.first == 0 && xy.second == 0) xy.first = 1;
|
|
|
|
if(xy.first == 1 && xy.second == 0) {
|
2018-04-09 16:05:23 +00:00
|
|
|
if(gp::on) restartGame(rg::bitrunc);
|
|
|
|
if(!nonbitrunc) restartGame(rg::bitrunc);
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
2018-04-13 12:50:40 +00:00
|
|
|
else if(xy.first == 1 && xy.second == 1) {
|
2018-04-09 16:05:23 +00:00
|
|
|
if(gp::on) restartGame(rg::bitrunc);
|
|
|
|
if(nonbitrunc) restartGame(rg::bitrunc);
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-04-09 16:05:23 +00:00
|
|
|
if(nonbitrunc) restartGame(rg::bitrunc);
|
2018-04-13 12:50:40 +00:00
|
|
|
param = xy;
|
2018-04-09 16:05:23 +00:00
|
|
|
restartGame(rg::gp);
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
2018-04-18 18:53:37 +00:00
|
|
|
#if CAP_TEXTURE
|
2018-04-10 03:12:40 +00:00
|
|
|
if(texture_remap)
|
|
|
|
texture::config.remap(old_tstate, old_tstate_max);
|
2018-04-18 18:53:37 +00:00
|
|
|
#endif
|
2018-04-03 21:25:43 +00:00
|
|
|
screens = g;
|
|
|
|
}
|
|
|
|
|
|
|
|
string helptext() {
|
|
|
|
return
|
2018-04-10 03:12:40 +00:00
|
|
|
"Goldberg polyhedra are obtained by adding extra hexagons to a dodecahedron. "
|
|
|
|
"GP(x,y) means that, to get to a nearest non-hex from any non-hex, you should move x "
|
2018-04-03 21:25:43 +00:00
|
|
|
"cells in any direction, turn right 60 degrees, and move y cells. "
|
2018-04-10 03:12:40 +00:00
|
|
|
"HyperRogue generalizes this to any tesselation with 3 faces per vertex. "
|
|
|
|
"By default HyperRogue uses bitruncation, which corresponds to GP(1,1).";
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 03:12:40 +00:00
|
|
|
void show(bool texture_remap) {
|
2018-04-03 21:25:43 +00:00
|
|
|
cmode = sm::SIDE;
|
|
|
|
gamescreen(0);
|
2018-04-10 03:12:40 +00:00
|
|
|
dialog::init(XLAT("Goldberg"));
|
2018-04-03 21:25:43 +00:00
|
|
|
|
2018-04-10 03:12:40 +00:00
|
|
|
bool show_nonthree = !(texture_remap && (S7&1));
|
|
|
|
|
|
|
|
if(show_nonthree) {
|
|
|
|
dialog::addBoolItem(XLAT("OFF"), param == loc(1,0), 'a');
|
|
|
|
dialog::lastItem().value = "GP(1,0)";
|
|
|
|
}
|
2018-04-03 21:25:43 +00:00
|
|
|
|
|
|
|
dialog::addBoolItem(XLAT("bitruncated"), param == loc(1,1), 'b');
|
2018-04-10 03:12:40 +00:00
|
|
|
dialog::lastItem().value = "GP(1,1)";
|
2018-04-03 21:25:43 +00:00
|
|
|
|
2018-04-10 03:12:40 +00:00
|
|
|
if(show_nonthree) {
|
|
|
|
dialog::addBoolItem(XLAT("chamfered"), param == loc(2,0), 'c');
|
|
|
|
dialog::lastItem().value = "GP(2,0)";
|
|
|
|
}
|
2018-04-03 21:25:43 +00:00
|
|
|
|
|
|
|
dialog::addBoolItem(XLAT("2x bitruncated"), param == loc(3,0), 'd');
|
2018-04-10 03:12:40 +00:00
|
|
|
dialog::lastItem().value = "GP(3,0)";
|
2018-04-03 21:25:43 +00:00
|
|
|
|
|
|
|
dialog::addBreak(100);
|
2018-04-13 12:50:40 +00:00
|
|
|
dialog::addSelItem("x", its(config.first), 'x');
|
|
|
|
dialog::addSelItem("y", its(config.second), 'y');
|
2018-04-03 21:25:43 +00:00
|
|
|
|
2018-04-13 12:50:40 +00:00
|
|
|
if((config.first-config.second)%3 && !show_nonthree)
|
2018-04-10 03:12:40 +00:00
|
|
|
dialog::addInfo("This pattern needs x-y divisible by 3");
|
|
|
|
else
|
2018-04-13 12:50:40 +00:00
|
|
|
dialog::addBoolItem(XLAT("select"), param == internal_representation(config), 'f');
|
2018-04-10 03:12:40 +00:00
|
|
|
|
2018-04-03 21:25:43 +00:00
|
|
|
dialog::addBreak(100);
|
2018-04-10 03:20:03 +00:00
|
|
|
dialog::addItem(XLAT("help"), SDLK_F1);
|
2018-04-03 21:25:43 +00:00
|
|
|
dialog::addItem(XLAT("back"), '0');
|
|
|
|
dialog::display();
|
|
|
|
|
2018-04-10 03:12:40 +00:00
|
|
|
keyhandler = [show_nonthree, texture_remap] (int sym, int uni) {
|
2018-04-03 21:25:43 +00:00
|
|
|
dialog::handleNavigation(sym, uni);
|
2018-04-10 03:12:40 +00:00
|
|
|
if(uni == 'a' && show_nonthree)
|
2018-04-13 12:50:40 +00:00
|
|
|
whirl_set(loc(1, 0), texture_remap);
|
2018-04-03 21:25:43 +00:00
|
|
|
else if(uni == 'b')
|
2018-04-13 12:50:40 +00:00
|
|
|
whirl_set(loc(1, 1), texture_remap);
|
2018-04-10 03:12:40 +00:00
|
|
|
else if(uni == 'c' && show_nonthree)
|
2018-04-13 12:50:40 +00:00
|
|
|
whirl_set(loc(2, 0), texture_remap);
|
2018-04-03 21:25:43 +00:00
|
|
|
else if(uni == 'd')
|
2018-04-13 12:50:40 +00:00
|
|
|
whirl_set(loc(3, 0), texture_remap);
|
|
|
|
else if(uni == 'f' && (show_nonthree || (config.first-config.second)%3 == 0))
|
|
|
|
whirl_set(config, texture_remap);
|
2018-04-03 21:25:43 +00:00
|
|
|
else if(uni == 'x')
|
2018-04-13 12:50:40 +00:00
|
|
|
dialog::editNumber(config.first, 1, 10, 1, 1, "x", helptext());
|
2018-04-03 21:25:43 +00:00
|
|
|
else if(uni == 'y')
|
2018-04-13 12:50:40 +00:00
|
|
|
dialog::editNumber(config.second, 1, 10, 1, 1, "y", helptext());
|
|
|
|
else if(uni == 'z')
|
|
|
|
swap(config.first, config.second);
|
2018-04-10 03:20:03 +00:00
|
|
|
else if(uni == '?' || sym == SDLK_F1 || uni == 'h' || uni == '2')
|
|
|
|
gotoHelp(helptext());
|
2018-04-03 21:25:43 +00:00
|
|
|
else if(doexiton(sym, uni))
|
|
|
|
popScreen();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-10 15:06:04 +00:00
|
|
|
loc univ_param() {
|
|
|
|
if(on) return param;
|
|
|
|
else if(nonbitrunc) return loc(1,0);
|
|
|
|
else return loc(1,1);
|
|
|
|
}
|
|
|
|
|
2018-04-10 03:12:40 +00:00
|
|
|
void configure(bool texture_remap = false) {
|
2018-04-10 15:06:04 +00:00
|
|
|
auto l = univ_param();
|
2018-04-13 12:50:40 +00:00
|
|
|
param = l;
|
|
|
|
config = human_representation(l);
|
2018-04-10 03:12:40 +00:00
|
|
|
pushScreen([texture_remap] () { gp::show(texture_remap); });
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
2018-04-06 20:22:33 +00:00
|
|
|
|
2018-04-10 22:55:05 +00:00
|
|
|
void be_in_triangle(local_info& li) {
|
2018-04-10 06:05:35 +00:00
|
|
|
int sp = 0;
|
|
|
|
auto& at = li.relative;
|
|
|
|
again:
|
|
|
|
auto corner = corners * loctoh_ort(at);
|
|
|
|
if(corner[1] < -1e-6 || corner[2] < -1e-6) {
|
|
|
|
at = at * eudir(1);
|
|
|
|
sp++;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if(sp>3) sp -= 6;
|
|
|
|
li.last_dir = fix7(li.last_dir - sp);
|
|
|
|
}
|
|
|
|
|
2018-04-10 15:06:04 +00:00
|
|
|
int length(loc p) {
|
|
|
|
return eudist(p.first, p.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
// from some point X, (0,0) is in distance dmain, param is in distance d0, and param*z is in distance d1
|
|
|
|
// what is the distance of at from X?
|
|
|
|
|
|
|
|
int solve_triangle(int dmain, int d0, int d1, loc at) {
|
|
|
|
loc centerloc(0, 0);
|
|
|
|
auto rel = make_pair(d0-dmain, d1-dmain);
|
|
|
|
if(center_locs.count(rel))
|
|
|
|
centerloc = center_locs[rel];
|
|
|
|
else {
|
|
|
|
bool found = false;
|
|
|
|
for(int y=-20; y<=20; y++)
|
|
|
|
for(int x=-20; x<=20; x++) {
|
|
|
|
loc c(x, y);
|
|
|
|
int cc = length(c);
|
|
|
|
int c0 = length(c - param);
|
|
|
|
int c1 = length(c - param*loc(0,1));
|
|
|
|
if(c0-cc == d0-dmain && c1-cc == d1-dmain)
|
|
|
|
found = true, centerloc = c;
|
|
|
|
}
|
|
|
|
if(!found)
|
|
|
|
printf("Warning: centerloc not found: %d,%d,%d\n", dmain, d0, d1);
|
|
|
|
center_locs[rel] = centerloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dmain + length(centerloc-at) - length(centerloc);
|
|
|
|
}
|
|
|
|
|
2018-04-12 18:53:50 +00:00
|
|
|
array<cell*, 3> get_masters(cell *c) {
|
|
|
|
if(gp::on) {
|
|
|
|
auto li = get_local_info(c);
|
|
|
|
be_in_triangle(li);
|
|
|
|
auto cm = c->master;
|
|
|
|
int i = li.last_dir;
|
|
|
|
return make_array(cm->c7, createStep(cm, i)->c7, createStep(cm, fix7(i+1))->c7);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return make_array(c->mov[0], c->mov[2], c->mov[4]);
|
|
|
|
}
|
|
|
|
|
2018-04-06 20:22:33 +00:00
|
|
|
int compute_dist(cell *c, int master_function(cell*)) {
|
|
|
|
auto li = get_local_info(c);
|
2018-04-10 22:55:05 +00:00
|
|
|
be_in_triangle(li);
|
2018-04-06 20:22:33 +00:00
|
|
|
|
|
|
|
cell *cm = c->master->c7;
|
|
|
|
|
|
|
|
int i = li.last_dir;
|
|
|
|
auto at = li.relative;
|
|
|
|
|
|
|
|
auto dmain = master_function(cm);
|
|
|
|
auto d0 = master_function(createStep(cm->master, i)->c7);
|
|
|
|
auto d1 = master_function(createStep(cm->master, fixdir(i+1, cm))->c7);
|
|
|
|
|
2018-04-10 15:06:04 +00:00
|
|
|
return solve_triangle(dmain, d0, d1, at);
|
|
|
|
}
|
|
|
|
|
|
|
|
int dist_2() {
|
|
|
|
return length(univ_param());
|
2018-04-06 20:22:33 +00:00
|
|
|
}
|
2018-04-10 15:06:04 +00:00
|
|
|
|
|
|
|
int dist_3() {
|
|
|
|
return length(univ_param() * loc(1,1));
|
|
|
|
}
|
|
|
|
|
|
|
|
int dist_1() {
|
|
|
|
return dist_3() - dist_2();
|
|
|
|
}
|
|
|
|
|
2018-04-03 21:25:43 +00:00
|
|
|
}
|
|
|
|
|