mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-11-08 09:42:59 +00:00
major rewrite: unified the common parts of heptagon and cell via struct connection<T> and struct walker<T>
This commit is contained in:
@@ -37,7 +37,7 @@ transmatrix master_relative(cell *c, bool get_inverse) {
|
||||
}
|
||||
}
|
||||
else if(!nonbitrunc && !euclid) {
|
||||
for(int d=0; d<S7; d++) if(c->master->c7->mov[d] == c)
|
||||
for(int d=0; d<S7; d++) if(c->master->c7->move(d) == c)
|
||||
return (get_inverse?invhexmove:hexmove)[d];
|
||||
return Id;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ transmatrix calc_relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hin
|
||||
t = eumovedir(2+i/2) * eumovedir(2+(i+1)/2) * t;
|
||||
else
|
||||
t = eumovedir(2+i/2) * t;
|
||||
if(c2->mirror(i)) mirrors++;
|
||||
if(c2->c.mirror(i)) mirrors++;
|
||||
c2 = c3;
|
||||
goto approach;
|
||||
}
|
||||
@@ -122,16 +122,16 @@ transmatrix calc_relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hin
|
||||
if(quotient & qSMALL) {
|
||||
transmatrix T;
|
||||
ld bestdist = 1e9;
|
||||
for(int d=0; d<S7; d++) if(h2->move[d]) {
|
||||
int sp = h2->spin(d);
|
||||
for(int d=0; d<S7; d++) if(h2->move(d)) {
|
||||
int sp = h2->c.spin(d);
|
||||
transmatrix S = heptmove[sp] * spin(2*M_PI*d/S7);
|
||||
if(h2->move[d] == h1) {
|
||||
if(h2->move(d) == h1) {
|
||||
transmatrix T1 = gm * S * where;
|
||||
auto curdist = hdist(tC0(T1), point_hint);
|
||||
if(curdist < bestdist) T = T1, bestdist = curdist;
|
||||
}
|
||||
for(int e=0; e<S7; e++) if(h2->move[d]->move[e] == h1) {
|
||||
int sp2 = h2->move[d]->spin(e);
|
||||
for(int e=0; e<S7; e++) if(h2->move(d)->move(e) == h1) {
|
||||
int sp2 = h2->move(d)->c.spin(e);
|
||||
transmatrix T1 = gm * heptmove[sp2] * spin(2*M_PI*e/S7) * S * where;
|
||||
auto curdist = hdist(tC0(T1), point_hint);
|
||||
if(curdist < bestdist) T = T1, bestdist = curdist;
|
||||
@@ -139,28 +139,28 @@ transmatrix calc_relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hin
|
||||
}
|
||||
if(bestdist < 1e8) return T;
|
||||
}
|
||||
for(int d=0; d<S7; d++) if(h2->move[d] == h1) {
|
||||
int sp = h2->spin(d);
|
||||
for(int d=0; d<S7; d++) if(h2->move(d) == h1) {
|
||||
int sp = h2->c.spin(d);
|
||||
return gm * heptmove[sp] * spin(2*M_PI*d/S7) * where;
|
||||
}
|
||||
if(geometry == gFieldQuotient) {
|
||||
int bestdist = 1000, bestd = 0;
|
||||
for(int d=0; d<S7; d++) {
|
||||
int dist = celldistance(h2->move[d]->c7, c1);
|
||||
int dist = celldistance(h2->move(d)->c7, c1);
|
||||
if(dist < bestdist) bestdist = dist, bestd = d;
|
||||
}
|
||||
int sp = h2->spin(bestd);
|
||||
int sp = h2->c.spin(bestd);
|
||||
where = heptmove[sp] * spin(2*M_PI*bestd/S7) * where;
|
||||
h2 = h2->move[bestd];
|
||||
h2 = h2->move(bestd);
|
||||
}
|
||||
else if(h1->distance < h2->distance) {
|
||||
int sp = h2->spin(0);
|
||||
h2 = h2->move[0];
|
||||
int sp = h2->c.spin(0);
|
||||
h2 = h2->move(0);
|
||||
where = heptmove[sp] * where;
|
||||
}
|
||||
else {
|
||||
int sp = h1->spin(0);
|
||||
h1 = h1->move[0];
|
||||
int sp = h1->c.spin(0);
|
||||
h1 = h1->move(0);
|
||||
gm = gm * invheptmove[sp];
|
||||
}
|
||||
}
|
||||
@@ -180,14 +180,14 @@ transmatrix calc_relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hin
|
||||
transmatrix &ggmatrix(cell *c) {
|
||||
transmatrix& t = gmatrix[c];
|
||||
if(t[2][2] == 0) {
|
||||
if(torus && centerover.c)
|
||||
t = calc_relative_matrix(c, centerover.c, C0);
|
||||
if(torus && centerover.at)
|
||||
t = calc_relative_matrix(c, centerover.at, C0);
|
||||
else if(euclid) {
|
||||
if(!centerover.c) centerover = cwt;
|
||||
if(!centerover.at) centerover = cwt;
|
||||
t = View * eumove(cell_to_vec(c) - cellwalker_to_vec(centerover));
|
||||
}
|
||||
else
|
||||
t = actualV(viewctr, cview()) * calc_relative_matrix(c, viewctr.h->c7, C0);
|
||||
t = actualV(viewctr, cview()) * calc_relative_matrix(c, viewctr.at->c7, C0);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
@@ -200,21 +200,21 @@ transmatrix calc_relative_matrix_help(cell *c, heptagon *h1) {
|
||||
auto li = gp::get_local_info(c);
|
||||
where = gp::Tf[li.last_dir][li.relative.first&31][li.relative.second&31][fix6(li.total_dir)];
|
||||
}
|
||||
else if(!nonbitrunc) for(int d=0; d<S7; d++) if(h2->c7->mov[d] == c)
|
||||
else if(!nonbitrunc) for(int d=0; d<S7; d++) if(h2->c7->move(d) == c)
|
||||
where = hexmove[d];
|
||||
// always add to last!
|
||||
while(h1 != h2) {
|
||||
for(int d=0; d<S7; d++) if(h1->move[d] == h2) printf("(adj) ");
|
||||
for(int d=0; d<S7; d++) if(h1->move(d) == h2) printf("(adj) ");
|
||||
if(h1->distance < h2->distance) {
|
||||
int sp = h2->spin(0);
|
||||
int sp = h2->c.spin(0);
|
||||
printf("A%d ", sp);
|
||||
h2 = h2->move[0];
|
||||
h2 = h2->move(0);
|
||||
where = heptmove[sp] * where;
|
||||
}
|
||||
else {
|
||||
int sp = h1->spin(0);
|
||||
int sp = h1->c.spin(0);
|
||||
printf("B%d ", sp);
|
||||
h1 = h1->move[0];
|
||||
h1 = h1->move(0);
|
||||
gm = gm * invheptmove[sp];
|
||||
}
|
||||
}
|
||||
@@ -262,16 +262,14 @@ void virtualRebase(cell*& base, T& at, bool tohex, const U& check) {
|
||||
transmatrix bestV;
|
||||
|
||||
for(int d=0; d<S7; d++) {
|
||||
heptspin hs;
|
||||
hs.h = h;
|
||||
hs.spin = d;
|
||||
heptspin hs(h, d, false);
|
||||
heptspin hs2 = hs + wstep;
|
||||
transmatrix V2 = spin(-hs2.spin*2*M_PI/S7) * invheptmove[d];
|
||||
double newz = check(V2 * at) [2];
|
||||
if(newz < currz) {
|
||||
currz = newz;
|
||||
bestV = V2;
|
||||
newbase = hs2.h->c7;
|
||||
newbase = hs2.at->c7;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +280,7 @@ void virtualRebase(cell*& base, T& at, bool tohex, const U& check) {
|
||||
else {
|
||||
if(tohex && !nonbitrunc) for(int d=0; d<S7; d++) {
|
||||
cell *c = createMov(base, d);
|
||||
transmatrix V2 = spin(-base->spn(d)*2*M_PI/S6) * invhexmove[d];
|
||||
transmatrix V2 = spin(-base->c.spin(d)*2*M_PI/S6) * invhexmove[d];
|
||||
double newz = check(V2 *at) [2];
|
||||
if(newz < currz) {
|
||||
currz = newz;
|
||||
@@ -310,14 +308,14 @@ void virtualRebase(cell*& base, hyperpoint& h, bool tohex) {
|
||||
}
|
||||
|
||||
double cellgfxdist(cell *c, int i) {
|
||||
if(gp::on || irr::on) return hdist0(tC0(calc_relative_matrix(c->mov[i], c, i)));
|
||||
if(gp::on || irr::on) return hdist0(tC0(calc_relative_matrix(c->move(i), c, i)));
|
||||
return nonbitrunc ? tessf * gp::scale : (c->type == 6 && (i&1)) ? hexhexdist : crossf;
|
||||
}
|
||||
|
||||
transmatrix cellrelmatrix(cell *c, int i) {
|
||||
if(gp::on) return calc_relative_matrix(c->mov[i], c, i);
|
||||
if(gp::on) return calc_relative_matrix(c->move(i), c, i);
|
||||
double d = cellgfxdist(c, i);
|
||||
return ddspin(c, i) * xpush(d) * iddspin(c->mov[i], c->spin(i), euclid ? 0 : S42);
|
||||
return ddspin(c, i) * xpush(d) * iddspin(c->move(i), c->c.spin(i), euclid ? 0 : S42);
|
||||
}
|
||||
|
||||
double randd() { return (rand() + .5) / (RAND_MAX + 1.); }
|
||||
@@ -375,9 +373,9 @@ hyperpoint get_corner_position(cell *c, int cid, ld cf) {
|
||||
hyperpoint hypercorner(cell *c, gp::local_info& li, int i) {
|
||||
cellwalker cw(c, i);
|
||||
cw += wstep;
|
||||
transmatrix cwm = calc_relative_matrix(cw.c, c, i);
|
||||
transmatrix cwm = calc_relative_matrix(cw.at, c, i);
|
||||
if(elliptic && cwm[2][2] < 0) cwm = centralsym * cwm;
|
||||
return cwm * gp::get_corner_position(cw.c, (cw+2).spin);
|
||||
return cwm * gp::get_corner_position(cw.at, (cw+2).spin);
|
||||
}
|
||||
|
||||
hyperpoint midcorner(cell *c, int i, ld v) {
|
||||
@@ -407,7 +405,7 @@ hyperpoint nearcorner(cell *c, int i) {
|
||||
if(gp::on) {
|
||||
cellwalker cw(c, i);
|
||||
cw += wstep;
|
||||
transmatrix cwm = calc_relative_matrix(cw.c, c, i);
|
||||
transmatrix cwm = calc_relative_matrix(cw.at, c, i);
|
||||
if(elliptic && cwm[2][2] < 0) cwm = centralsym * cwm;
|
||||
return cwm * C0;
|
||||
}
|
||||
@@ -447,9 +445,9 @@ hyperpoint farcorner(cell *c, int i, int which) {
|
||||
cellwalker cw(c, i);
|
||||
int hint = cw.spin;
|
||||
cw += wstep;
|
||||
transmatrix cwm = calc_relative_matrix(cw.c, c, hint);
|
||||
transmatrix cwm = calc_relative_matrix(cw.at, c, hint);
|
||||
// hyperpoint nfar = cwm*C0;
|
||||
auto li1 = gp::get_local_info(cw.c);
|
||||
auto li1 = gp::get_local_info(cw.at);
|
||||
if(which == 0)
|
||||
return cwm * get_corner_position(li1, (cw+2).spin);
|
||||
if(which == 1)
|
||||
|
||||
Reference in New Issue
Block a user