1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-25 01:20:37 +00:00

euc:: further cleanup

This commit is contained in:
Zeno Rogue 2019-12-08 11:25:14 +01:00
parent e8a39e6663
commit 206dc25ed6
2 changed files with 48 additions and 41 deletions

View File

@ -28,7 +28,8 @@ EX namespace euc {
typedef array<coord, 3> intmatrix; typedef array<coord, 3> intmatrix;
#endif #endif
EX coord euzero = coord(0,0,0); EX const coord euzero = coord(0,0,0);
EX const coord eutester = coord(3,7,0);
EX intmatrix euzeroall = make_array<coord>(euzero, euzero, euzero); EX intmatrix euzeroall = make_array<coord>(euzero, euzero, euzero);
static const intmatrix main_axes = make_array<coord>(coord(1,0,0), coord(0,1,0), coord(0,0,1)); static const intmatrix main_axes = make_array<coord>(coord(1,0,0), coord(0,1,0), coord(0,0,1));
@ -70,7 +71,7 @@ EX namespace euc {
return shifttable; return shifttable;
} }
EX coord canonicalize(coord x); EX coord basic_canonicalize(coord x);
#if HDR #if HDR
struct canonical_t { struct canonical_t {
@ -114,6 +115,9 @@ EX namespace euc {
intmatrix inverse_axes; intmatrix inverse_axes;
/** struct for canonicalization */ /** struct for canonicalization */
canonical_t canonical; canonical_t canonical;
/** canonicalize coord x; in case of twisting, adjust d, M, and mirr accordingly */
void canonicalize(coord& x, coord& d, transmatrix& M, bool& mirr);
}; };
#endif #endif
EX torus_config eu_input, eu_edit; EX torus_config eu_input, eu_edit;
@ -176,24 +180,21 @@ EX namespace euc {
} }
} }
heptagon *build(heptagon *parent, int d, coord at) { heptagon *create_step(heptagon *parent, int d) override {
auto h = get_at(at);
int d1 = (d+S7/2)%S7; int d1 = (d+S7/2)%S7;
bool mirr = false; bool mirr = false;
if(eu.twisted) {
transmatrix I; transmatrix I;
auto v = ispacemap[parent] + shifttable[d];
auto st = shifttable[d1]; auto st = shifttable[d1];
twist(ispacemap[parent] + shifttable[d], st, I, mirr); eu.canonicalize(v, st, I, mirr);
if(eu.twisted)
for(int i=0; i<S7; i++) if(shifttable[i] == st) d1 = i; for(int i=0; i<S7; i++) if(shifttable[i] == st) d1 = i;
}
heptagon *h = get_at(v);
h->c.connect(d1, parent, d, mirr); h->c.connect(d1, parent, d, mirr);
return h; return h;
} }
heptagon *create_step(heptagon *parent, int d) override {
return build(parent, d, canonicalize(ispacemap[parent] + shifttable[d]));
}
transmatrix adj(heptagon *h, int i) override { transmatrix adj(heptagon *h, int i) override {
if(!eu.twisted) return tmatrix[i]; if(!eu.twisted) return tmatrix[i];
transmatrix res = tmatrix[i]; transmatrix res = tmatrix[i];
@ -201,7 +202,7 @@ EX namespace euc {
id += shifttable[i]; id += shifttable[i];
auto dummy = euzero; auto dummy = euzero;
bool dm = false; bool dm = false;
twist(id, dummy, res, dm); eu.canonicalize(id, dummy, res, dm);
return res; return res;
} }
@ -251,12 +252,12 @@ EX namespace euc {
I = I * eumove(co); I = I * eumove(co);
auto dummy = euzero; auto dummy = euzero;
bool dm = false; bool dm = false;
cs = twist(cs, dummy, I, dm); eu.canonicalize(cs, dummy, I, dm);
} }
return T; return T;
} }
auto d = ispacemap[h2] - ispacemap[h1]; auto d = ispacemap[h2] - ispacemap[h1];
d = canonicalize(d); d = basic_canonicalize(d);
return eumove(d); return eumove(d);
} }
@ -370,7 +371,7 @@ EX namespace euc {
EX int celldistance(cell *c1, cell *c2) { EX int celldistance(cell *c1, cell *c2) {
auto cm = cubemap(); auto cm = cubemap();
return celldistance(canonicalize(cm->ispacemap[c1->master] - cm->ispacemap[c2->master])); return celldistance(basic_canonicalize(cm->ispacemap[c1->master] - cm->ispacemap[c2->master]));
} }
EX void set_land(cell *c) { EX void set_land(cell *c) {
@ -597,8 +598,18 @@ EX namespace euc {
- b[0]*a[1] - b[1]*a[2] - b[2]*a[0]; - b[0]*a[1] - b[1]*a[2] - b[2]*a[0];
}; };
EX coord twist(coord x, coord& d, transmatrix& M, bool& mirr) { void torus_config_full::canonicalize(coord& x, coord& d, transmatrix& M, bool& mirr) {
if(!eu.twisted) return x; if(!twisted) {
if(eu.infinite_dims == WDIM) return;
if(eu.infinite_dims == WDIM-1) {
auto& o = eu.optimal_axes;
while(celldistance(x + o[0]) <= celldistance(x)) x += o[0];
while(celldistance(x - o[0]) < celldistance(x)) x -= o[0];
return;
}
x = eu.canonical.get(x);
return;
}
auto& T0 = eu.user_axes; auto& T0 = eu.user_axes;
if(eu.twisted & 16) { if(eu.twisted & 16) {
int period = T0[2][2]; int period = T0[2][2];
@ -630,7 +641,7 @@ EX namespace euc {
while(diagonal_cross(coo, T0[0]) > 0) coo -= T0[1]; while(diagonal_cross(coo, T0[0]) > 0) coo -= T0[1];
while(diagonal_cross(coo, T0[0]) < 0) coo += T0[1]; while(diagonal_cross(coo, T0[0]) < 0) coo += T0[1];
} }
return coo; return;
} }
if(WDIM == 3) { if(WDIM == 3) {
auto& coo = x; auto& coo = x;
@ -648,7 +659,7 @@ EX namespace euc {
} }
for(int i: {0,1}) for(int i: {0,1})
if(T0[i][i]) coo[i] = gmod(coo[i], T0[i][i]); if(T0[i][i]) coo[i] = gmod(coo[i], T0[i][i]);
return coo; return;
} }
else { else {
gp::loc coo = to_loc(x); gp::loc coo = to_loc(x);
@ -683,26 +694,18 @@ EX namespace euc {
} }
} }
d[0] = d0.first; d[1] = d0.second; d[0] = d0.first; d[1] = d0.second;
return to_coord(coo); x = to_coord(coo);
return;
} }
} }
coord canonicalize(coord x) { coord basic_canonicalize(coord x) {
if(eu.twisted) {
transmatrix M = Id; transmatrix M = Id;
auto dummy = euzero; auto dummy = euzero;
bool dm = false; bool dm = false;
return twist(x, dummy, M, dm); eu.canonicalize(x, dummy, M, dm);
}
if(eu.infinite_dims == WDIM) return x;
if(eu.infinite_dims == WDIM-1) {
auto& o = eu.optimal_axes;
while(celldistance(x + o[0]) <= celldistance(x)) x += o[0];
while(celldistance(x - o[0]) < celldistance(x)) x -= o[0];
return x; return x;
} }
return eu.canonical.get(x);
}
EX void prepare_torus3() { EX void prepare_torus3() {
eu_edit = eu_input; eu_edit = eu_input;
@ -1106,8 +1109,8 @@ EX int dist(gp::loc a, gp::loc b) {
} }
EX int cyldist(gp::loc a, gp::loc b) { EX int cyldist(gp::loc a, gp::loc b) {
a = to_loc(canonicalize(to_coord(a))); a = to_loc(basic_canonicalize(to_coord(a)));
b = to_loc(canonicalize(to_coord(b))); b = to_loc(basic_canonicalize(to_coord(b)));
if(!quotient) return dist(a, b); if(!quotient) return dist(a, b);

View File

@ -267,8 +267,12 @@ EX namespace models {
for(int y=0; y<=200; y++) for(int y=0; y<=200; y++)
for(int x=-200; x<=200; x++) { for(int x=-200; x<=200; x++) {
if(y == 0 && x <= 0) continue; if(y == 0 && x <= 0) continue;
auto zero = euc::canonicalize(euc::to_coord(gp::loc{x, y})); transmatrix dummy = Id;
if(zero == euc::euzero) euc::coord v(x, y, 0);
bool mirr = false;
auto t = euc::eutester;
euc::eu.canonicalize(v, t, dummy, mirr);
if(v == euc::euzero && t == euc::eutester)
torus_zeros.emplace_back(x, y); torus_zeros.emplace_back(x, y);
} }
sort(torus_zeros.begin(), torus_zeros.end(), [] (const gp::loc p1, const gp::loc p2) { sort(torus_zeros.begin(), torus_zeros.end(), [] (const gp::loc p1, const gp::loc p2) {