1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-27 14:37:16 +00:00

cleanup in Euclidean

This commit is contained in:
Zeno Rogue 2019-12-08 10:59:09 +01:00
parent fe180cb6c3
commit ddb5d07ff6
17 changed files with 262 additions and 227 deletions

View File

@ -59,6 +59,8 @@ EX int celldistAltRelative(cell *c) {
return celldistAlt(c) - roundTableRadius(c); return celldistAlt(c) - roundTableRadius(c);
} }
EX gp::loc camelot_coords() { return gp::loc(a4 ? 21 : 20, 10); }
EX int euclidAlt(short x, short y) { EX int euclidAlt(short x, short y) {
if(among(specialland, laTemple, laClearing, laCanvas)) { if(among(specialland, laTemple, laClearing, laCanvas)) {
if(euclid6) if(euclid6)
@ -82,20 +84,20 @@ EX int euclidAlt(short x, short y) {
return 3 - min(abs(x), abs(y)); return 3 - min(abs(x), abs(y));
} }
else if(specialland == laPrincessQuest) else if(specialland == laPrincessQuest)
return eudist(x-EPX, y-EPY); return euc::dist(gp::loc(x,y), princess::coords());
else return eudist(x-(a4 ? 21 : 20), y-10); else return euc::dist(gp::loc(x,y), camelot_coords());
} }
EX int cylinder_alt(cell *c) { EX int cylinder_alt(cell *c) {
if(specialland == laPrincessQuest) if(specialland == laPrincessQuest)
return celldistance(c, at_euc2_coordinates({EPX, EPY})); return celldistance(c, euc::at(princess::coords()));
if(specialland == laCamelot) if(specialland == laCamelot)
return celldistance(c, at_euc2_coordinates({21, 10})); return celldistance(c, euc::at(camelot_coords()));
int maxmul = 0; int maxmul = 0;
for(int d = 0; d < SG6; d++) for(int d = 0; d < SG6; d++)
maxmul = max(maxmul, dcross(sdxy(), gp::eudir(d))); maxmul = max(maxmul, euc::dcross(euc::sdxy(), gp::eudir(d)));
return 5-abs(gdiv(dcross(sdxy(), euc2_coordinates(c)), maxmul)); return 5-abs(gdiv(euc::dcross(euc::sdxy(), euc2_coordinates(c)), maxmul));
} }
const int NOCOMPASS = 1000000; const int NOCOMPASS = 1000000;

View File

@ -914,7 +914,7 @@ EX int celldistance3_hex(heptagon *c1, heptagon *c2) {
int sx = int(floor(h[0] - h[1] / sqrt(3) + .5)) / 3; int sx = int(floor(h[0] - h[1] / sqrt(3) + .5)) / 3;
int sy = int(floor(h[1] * 2 / sqrt(3) + .5)) / 3; int sy = int(floor(h[1] * 2 / sqrt(3) + .5)) / 3;
int ysteps = xsteps + eudist(sx, sy); int ysteps = xsteps + euc::dist(sx, sy);
if(ysteps < steps) steps = ysteps; if(ysteps < steps) steps = ysteps;
if(sx >= 8 || sx <= -8 || sy >= 8 || sy <= -8) break; if(sx >= 8 || sx <= -8 || sy >= 8 || sy <= -8) break;
} }

View File

@ -796,7 +796,7 @@ cdata *getHeptagonCdata(heptagon *h) {
cdata *getEuclidCdata(gp::loc h) { cdata *getEuclidCdata(gp::loc h) {
int x = h.first, y = h.second; int x = h.first, y = h.second;
auto& data = archimedean ? arcm::get_cdata() : get_cdata(); auto& data = archimedean ? arcm::get_cdata() : euc::get_cdata();
// hrmap_euclidean* euc = dynamic_cast<hrmap_euclidean*> (currentmap); // hrmap_euclidean* euc = dynamic_cast<hrmap_euclidean*> (currentmap);
if(data.count(h)) return &(data[h]); if(data.count(h)) return &(data[h]);
@ -1013,7 +1013,7 @@ EX int celldistance(cell *c1, cell *c2) {
#endif #endif
if(euclid && WDIM == 2 && !penrose && !archimedean) { if(euclid && WDIM == 2 && !penrose && !archimedean) {
return cyldist(euc2_coordinates(c1), euc2_coordinates(c2)); return euc::cyldist(euc2_coordinates(c1), euc2_coordinates(c2));
} }
if(archimedean || quotient || solnih || (penrose && euclid) || experimental || sl2 || nil) { if(archimedean || quotient || solnih || (penrose && euclid) || experimental || sl2 || nil) {

View File

@ -1782,7 +1782,7 @@ void celldrawer::draw_cellstat() {
} }
if(cmode & sm::TORUSCONFIG) { if(cmode & sm::TORUSCONFIG) {
auto p = coord_display(V, c); auto p = euc::coord_display(V, c);
if(p.second != "") if(p.second != "")
queuestr(V, p.first ? .2 : .6, p.second, p.first ? 0xFFFFFFD0 : 0xFFFF0040, 1); queuestr(V, p.first ? .2 : .6, p.second, p.first ? 0xFFFFFFD0 : 0xFFFF0040, 1);
} }

View File

@ -479,9 +479,6 @@ EX namespace elec {
EX namespace princess { EX namespace princess {
#if HDR #if HDR
#define EPX 39
#define EPY 21
#define OUT_OF_PRISON 200 #define OUT_OF_PRISON 200
#define OUT_OF_PALACE 250 #define OUT_OF_PALACE 250
#define PRADIUS0 (141) #define PRADIUS0 (141)
@ -499,6 +496,8 @@ struct info {
#endif #endif
EX gp::loc coords() { return gp::loc(39, 21); }
EX bool generating = false; EX bool generating = false;
EX bool challenge = false; EX bool challenge = false;
EX bool saved = false; EX bool saved = false;

View File

@ -8,9 +8,7 @@
#include "hyper.h" #include "hyper.h"
namespace hr { namespace hr {
// 3D Euclidean space EX namespace euc {
EX namespace euclid3 {
#if HDR #if HDR
struct coord : array<int, 3> { struct coord : array<int, 3> {
@ -73,9 +71,53 @@ EX namespace euclid3 {
} }
EX coord canonicalize(coord x); EX coord canonicalize(coord x);
EX int twisted;
EX intmatrix T0; #if HDR
EX gp::loc twisted_vec, ortho_vec; struct canonical_t {
unordered_map<coord, int> hash;
vector<coord> seq;
int index;
canonical_t() { index = 0; }
void reset() { index = 0; }
void add(coord val);
coord get(coord x);
};
struct torus_config {
/** periods entered by the user */
intmatrix user_axes;
/** OR'ed flags: 1 -- flip X in 3D, 2 -- flip Y in 3D, 4 -- flip X/Y in 3D, 8 -- Klein bottle in 2D, 16 -- third turn in 3D */
int twisted;
torus_config() {}
torus_config(intmatrix user_axes, int twisted) : user_axes(user_axes), twisted(twisted) {}
};
struct torus_config_full : torus_config {
/** optimal representation of the periods */
intmatrix optimal_axes;
/** regular axes (?) */
intmatrix regular_axes;
/** in 2D: the period vector which is reflected */
gp::loc twisted_vec;
/** in 2D: a vector orthogonal to twisted_vec */
gp::loc ortho_vec;
/** determinant */
int det;
/** the number of infinite dimensions */
int infinite_dims;
/** ? */
intmatrix inverse_axes;
/** struct for canonicalization */
canonical_t canonical;
};
#endif
EX torus_config eu_input, eu_edit;
EX torus_config_full eu;
struct hrmap_euclid3 : hrmap_standard { struct hrmap_euclid3 : hrmap_standard {
vector<coord> shifttable; vector<coord> shifttable;
@ -138,7 +180,7 @@ EX namespace euclid3 {
auto h = get_at(at); auto h = get_at(at);
int d1 = (d+S7/2)%S7; int d1 = (d+S7/2)%S7;
bool mirr = false; bool mirr = false;
if(twisted) { if(eu.twisted) {
transmatrix I; transmatrix I;
auto st = shifttable[d1]; auto st = shifttable[d1];
twist(ispacemap[parent] + shifttable[d], st, I, mirr); twist(ispacemap[parent] + shifttable[d], st, I, mirr);
@ -153,7 +195,7 @@ EX namespace euclid3 {
} }
transmatrix adj(heptagon *h, int i) override { transmatrix adj(heptagon *h, int i) override {
if(!twisted) return tmatrix[i]; if(!eu.twisted) return tmatrix[i];
transmatrix res = tmatrix[i]; transmatrix res = tmatrix[i];
coord id = ispacemap[h]; coord id = ispacemap[h];
id += shifttable[i]; id += shifttable[i];
@ -187,7 +229,7 @@ EX namespace euclid3 {
} }
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override { transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
if(twisted) { if(eu.twisted) {
if(h1 == h2) return Id; if(h1 == h2) return Id;
for(int s=0; s<S7; s++) if(h2 == h1->move(s)) return adj(h1, s); for(int s=0; s<S7; s++) if(h2 == h1->move(s)) return adj(h1, s);
coord c1 = ispacemap[h1]; coord c1 = ispacemap[h1];
@ -200,11 +242,11 @@ EX namespace euclid3 {
for(int a=-1; a<=1; a++) for(int a=-1; a<=1; a++)
for(int b=-1; b<=1; b++) { for(int b=-1; b<=1; b++) {
if(b && WDIM == 2) continue; if(b && WDIM == 2) continue;
transmatrix T1 = I * eumove((c2 - cs) + a*T0[0] + b*T0[1]); transmatrix T1 = I * eumove((c2 - cs) + a*eu.user_axes[0] + b*eu.user_axes[1]);
if(hdist(tC0(T1), hint) < hdist(tC0(T), hint)) if(hdist(tC0(T1), hint) < hdist(tC0(T), hint))
T = T1; T = T1;
} }
auto co = T0[WDIM-1]; auto co = eu.user_axes[WDIM-1];
cs += co; cs += co;
I = I * eumove(co); I = I * eumove(co);
auto dummy = euzero; auto dummy = euzero;
@ -378,59 +420,38 @@ EX namespace euclid3 {
return T2; return T2;
} }
intmatrix user_axes; EX torus_config torus3(int x, int y, int z) {
intmatrix optimal_axes; intmatrix T0 = euzeroall;
intmatrix regular_axes;
intmatrix T, T2, T_edit;
EX int det;
int infinite_dims;
EX int twisted0;
int twisted_edit;
EX void set_torus3(int x, int y, int z) {
for(int i=0; i<3; i++) for(int j=0; j<3; j++) T0[i][j] = 0;
tie(T0[0][0], T0[1][1], T0[2][2]) = make_tuple(x, y, z); tie(T0[0][0], T0[1][1], T0[2][2]) = make_tuple(x, y, z);
twisted = 0; return {T0, 0};
} }
EX void clear_torus3() { EX torus_config clear_torus3() {
set_torus3(0, 0, 0); return {euzeroall, 0};
} }
unordered_map<coord, int> canonical_hash; EX coord compute_cat(coord coo) {
vector<coord> canonical_seq;
int canonical_index;
coord compute_cat(coord coo) {
coord cat = euzero; coord cat = euzero;
auto& T2 = eu.inverse_axes;
for(int i=0; i<3; i++) { for(int i=0; i<3; i++) {
int val = T2[0][i] * coo[0] + T2[1][i] * coo[1] + T2[2][i] * coo[2]; int val = T2[0][i] * coo[0] + T2[1][i] * coo[1] + T2[2][i] * coo[2];
if(i < WDIM - infinite_dims) val = gmod(val, det); if(i < WDIM - eu.infinite_dims) val = gmod(val, eu.det);
cat += val * main_axes[i]; cat += val * main_axes[i];
} }
return cat; return cat;
}; };
void add_canonical(coord val) {
auto cat = compute_cat(val);
if(canonical_hash.count(cat)) return;
canonical_hash[cat] = isize(canonical_seq);
canonical_seq.push_back(val);
}
EX bool valid_third_turn(const intmatrix& m) { EX bool valid_third_turn(const intmatrix& m) {
if(T0[0][2] != -T0[0][0]-T0[0][1]) return false; if(m[0][2] != -m[0][0]-m[0][1]) return false;
if(T0[1][0] != T0[0][1]) return false; if(m[1][0] != m[0][1]) return false;
if(T0[1][1] != T0[0][2]) return false; if(m[1][1] != m[0][2]) return false;
if(T0[1][2] != T0[0][0]) return false; if(m[1][2] != m[0][0]) return false;
if(T0[2][0] != T0[2][1]) return false; if(m[2][0] != m[2][1]) return false;
if(T0[2][0] != T0[2][2]) return false; if(m[2][0] != m[2][2]) return false;
return true; return true;
} }
EX intmatrix make_third_turn(int a, int b, int c) { EX torus_config make_third_turn(int a, int b, int c) {
intmatrix T0; intmatrix T0;
T0[0][0] = a; T0[0][0] = a;
T0[0][1] = b; T0[0][1] = b;
@ -440,58 +461,72 @@ EX namespace euclid3 {
T0[1][1] = T0[0][2]; T0[1][1] = T0[0][2];
T0[1][2] = T0[0][0]; T0[1][2] = T0[0][0];
T0[2][1] = T0[2][2] = c; T0[2][1] = T0[2][2] = c;
return T0; return {T0, 8};
} }
EX intmatrix make_quarter_turn(int a, int b, int c) { EX torus_config make_quarter_turn(int a, int b, int c) {
intmatrix T0 = euzeroall; intmatrix T0 = euzeroall;
T0[0][0] = a; T0[0][0] = a;
T0[0][1] = b; T0[0][1] = b;
T0[2][0] = c; T0[2][0] = c;
return T0; return {T0, 5};
}
void canonical_t::add(coord val) {
auto cat = compute_cat(val); if(hash.count(cat)) return; hash[cat] = isize(seq); seq.push_back(val);
}
coord canonical_t::get(coord x) {
auto cat = compute_cat(x);
auto& st = cubemap()->shifttable;
while(!hash.count(cat)) {
if(index == isize(seq)) throw hr_exception();
auto v = seq[index++];
for(auto s: st) add(v + s);
}
return seq[hash[cat]];
} }
EX void build_torus3(eGeometry g) { EX void build_torus3(eGeometry g) {
int dim = ginf[g].g.gameplay_dimension; int dim = ginf[g].g.gameplay_dimension;
if(IRREGULAR) T0 = irr::base_periods, twisted0 = irr::base_twisted; // if(IRREGULAR) T0 = irr::base_periods, twisted0 = irr::base_twisted;
user_axes = T0; eu.user_axes = eu_input.user_axes;
if(dim == 2) user_axes[2] = euzero; if(dim == 2) eu.user_axes[2] = euzero;
optimal_axes = user_axes; eu.optimal_axes = eu.user_axes;
again: again:
for(int i=0; i<dim; i++) if(optimal_axes[i] < euzero) optimal_axes[i] = -optimal_axes[i]; for(int i=0; i<dim; i++) if(eu.optimal_axes[i] < euzero) eu.optimal_axes[i] = -eu.optimal_axes[i];
if(optimal_axes[0] < optimal_axes[1]) swap(optimal_axes[0], optimal_axes[1]); if(eu.optimal_axes[0] < eu.optimal_axes[1]) swap(eu.optimal_axes[0], eu.optimal_axes[1]);
if(optimal_axes[1] < optimal_axes[dim-1]) swap(optimal_axes[1], optimal_axes[dim-1]); if(eu.optimal_axes[1] < eu.optimal_axes[dim-1]) swap(eu.optimal_axes[1], eu.optimal_axes[dim-1]);
if(optimal_axes[0] < optimal_axes[1]) swap(optimal_axes[0], optimal_axes[1]); if(eu.optimal_axes[0] < eu.optimal_axes[1]) swap(eu.optimal_axes[0], eu.optimal_axes[1]);
for(int i=0; i<3; i++) { for(int i=0; i<3; i++) {
int i1 = (i+1) % 3; int i1 = (i+1) % 3;
int i2 = (i+2) % 3; int i2 = (i+2) % 3;
for(int a=-10; a<=10; a++) for(int a=-10; a<=10; a++)
for(int b=-10; b<=10; b++) { for(int b=-10; b<=10; b++) {
coord cand = optimal_axes[i] + optimal_axes[i1] * a + optimal_axes[i2] * b; coord cand = eu.optimal_axes[i] + eu.optimal_axes[i1] * a + eu.optimal_axes[i2] * b;
if(celldistance(cand) < celldistance(optimal_axes[i])) { if(celldistance(cand) < celldistance(eu.optimal_axes[i])) {
optimal_axes[i] = cand; eu.optimal_axes[i] = cand;
goto again; goto again;
} }
} }
} }
regular_axes = optimal_axes; eu.regular_axes = eu.optimal_axes;
infinite_dims = dim; eu.infinite_dims = dim;
for(int i=0; i<dim; i++) if(optimal_axes[i] != euzero) infinite_dims--; for(int i=0; i<dim; i++) if(eu.optimal_axes[i] != euzero) eu.infinite_dims--;
int attempt = 0; int attempt = 0;
next_attempt: next_attempt:
for(int i=dim-infinite_dims; i<3; i++) for(int i=dim-eu.infinite_dims; i<3; i++)
regular_axes[i] = main_axes[(attempt+i)%3]; eu.regular_axes[i] = main_axes[(attempt+i)%3];
T = regular_axes; eu.det = determinant(eu.regular_axes);
det = determinant(T); if(eu.det == 0) {
if(det == 0) {
attempt++; attempt++;
if(attempt == 3) { if(attempt == 3) {
println(hlog, "weird singular!\n"); println(hlog, "weird singular!\n");
@ -500,50 +535,49 @@ EX namespace euclid3 {
goto next_attempt; goto next_attempt;
} }
if(det < 0) det = -det; if(eu.det < 0) eu.det = -eu.det;
T2 = scaled_inverse(T); eu.inverse_axes = scaled_inverse(eu.regular_axes);
canonical_hash.clear(); eu.canonical.reset();
canonical_seq.clear(); eu.canonical.add(euzero);
canonical_index = 0;
add_canonical(euzero);
twisted = twisted0; eu.twisted = eu_input.twisted;
if(dim == 3) { if(dim == 3) {
if(valid_third_turn(T0)) { auto &T0 = eu.user_axes;
twisted &= 16; if(valid_third_turn(eu.user_axes)) {
if(g == gRhombic3 && (T0[2][2]&1)) twisted = 0; eu.twisted &= 16;
if(g == gBitrunc3 && (T0[0][0]&1)) twisted = 0; if(g == gRhombic3 && (T0[2][2]&1)) eu.twisted = 0;
if(g == gBitrunc3 && (T0[1][1]&1)) twisted = 0; if(g == gBitrunc3 && (T0[0][0]&1)) eu.twisted = 0;
if(g == gBitrunc3 && (T0[1][1]&1)) eu.twisted = 0;
} }
else { else {
twisted &= 7; eu.twisted &= 7;
if(g != gCubeTiling && ((T0[0][0]+T0[2][2]) & 1)) twisted &=~ 1; if(g != gCubeTiling && ((T0[0][0]+T0[2][2]) & 1)) eu.twisted &=~ 1;
if(g != gCubeTiling && ((T0[1][1]+T0[2][2]) & 1)) twisted &=~ 2; if(g != gCubeTiling && ((T0[1][1]+T0[2][2]) & 1)) eu.twisted &=~ 2;
for(int i=0; i<3; i++) for(int j=0; j<3; j++) for(int i=0; i<3; i++) for(int j=0; j<3; j++)
if(i != j && T0[i][j]) twisted = 0; if(i != j && T0[i][j]) eu.twisted = 0;
if(T0[2][2] == 0) twisted = 0; if(T0[2][2] == 0) eu.twisted = 0;
if(T0[0][0] != T0[1][1]) twisted &= 3; if(T0[0][0] != T0[1][1]) eu.twisted &= 3;
} }
} }
else { else {
twisted &= 8; eu.twisted &= 8;
twisted_vec = to_loc(T0[1]); eu.twisted_vec = to_loc(eu.user_axes[1]);
ortho_vec = to_loc(T0[0]); eu.ortho_vec = to_loc(eu.user_axes[0]);
if(twisted_vec == gp::loc{0,0}) twisted = 0; if(eu.twisted_vec == gp::loc{0,0}) eu.twisted = 0;
if(chiral(twisted_vec)) twisted = 0; if(chiral(eu.twisted_vec)) eu.twisted = 0;
if(dscalar(twisted_vec, ortho_vec)) if(dscalar(eu.twisted_vec, eu.ortho_vec))
twisted = 0; eu.twisted = 0;
} }
set_flag(ginf[g].flags, qANYQ, infinite_dims < dim); set_flag(ginf[g].flags, qANYQ, eu.infinite_dims < dim);
set_flag(ginf[g].flags, qBOUNDED, infinite_dims == 0); set_flag(ginf[g].flags, qBOUNDED, eu.infinite_dims == 0);
set_flag(ginf[g].flags, qSMALL, infinite_dims == 0 && det <= 4096); set_flag(ginf[g].flags, qSMALL, eu.infinite_dims == 0 && eu.det <= 4096);
bool nonori = false; bool nonori = false;
if(twisted&1) nonori = !nonori; if(eu.twisted&1) nonori = !nonori;
if(twisted&2) nonori = !nonori; if(eu.twisted&2) nonori = !nonori;
if(twisted&4) nonori = !nonori; if(eu.twisted&4) nonori = !nonori;
if(twisted&8) nonori = !nonori; if(eu.twisted&8) nonori = !nonori;
set_flag(ginf[g].flags, qNONORIENTABLE, nonori); set_flag(ginf[g].flags, qNONORIENTABLE, nonori);
} }
@ -564,8 +598,9 @@ EX namespace euclid3 {
}; };
EX coord twist(coord x, coord& d, transmatrix& M, bool& mirr) { EX coord twist(coord x, coord& d, transmatrix& M, bool& mirr) {
if(!twisted) return x; if(!eu.twisted) return x;
if(twisted & 16) { auto& T0 = eu.user_axes;
if(eu.twisted & 16) {
int period = T0[2][2]; int period = T0[2][2];
transmatrix RotYZX = Zero; transmatrix RotYZX = Zero;
RotYZX[1][0] = 1; RotYZX[1][0] = 1;
@ -601,15 +636,15 @@ EX namespace euclid3 {
auto& coo = x; auto& coo = x;
while(coo[2] >= T0[2][2]) { while(coo[2] >= T0[2][2]) {
coo[2] -= T0[2][2]; coo[2] -= T0[2][2];
if(twisted & 1) coo[0] *= -1, d[0] *= -1, M = M * MirrorX; if(eu.twisted & 1) coo[0] *= -1, d[0] *= -1, M = M * MirrorX;
if(twisted & 2) coo[1] *= -1, d[1] *= -1, M = M * MirrorY; if(eu.twisted & 2) coo[1] *= -1, d[1] *= -1, M = M * MirrorY;
if(twisted & 4) swap(coo[0], coo[1]), swap01(M), swap(d[0], d[1]); if(eu.twisted & 4) swap(coo[0], coo[1]), swap01(M), swap(d[0], d[1]);
} }
while(coo[2] < 0) { while(coo[2] < 0) {
coo[2] += T0[2][2]; coo[2] += T0[2][2];
if(twisted & 4) swap(coo[0], coo[1]), swap(d[0], d[1]), swap01(M); if(eu.twisted & 4) swap(coo[0], coo[1]), swap(d[0], d[1]), swap01(M);
if(twisted & 1) coo[0] *= -1, d[0] *= -1, M = M * MirrorX; if(eu.twisted & 1) coo[0] *= -1, d[0] *= -1, M = M * MirrorX;
if(twisted & 2) coo[1] *= -1, d[1] *= -1, M = M * MirrorY; if(eu.twisted & 2) coo[1] *= -1, d[1] *= -1, M = M * MirrorY;
} }
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]);
@ -617,14 +652,14 @@ EX namespace euclid3 {
} }
else { else {
gp::loc coo = to_loc(x); gp::loc coo = to_loc(x);
gp::loc ort = ort1() * twisted_vec; gp::loc ort = ort1() * eu.twisted_vec;
int dsc = dscalar(twisted_vec, twisted_vec); int dsc = dscalar(eu.twisted_vec, eu.twisted_vec);
gp::loc d0 (d[0], d[1]); gp::loc d0 (d[0], d[1]);
hyperpoint h = eumove(to_coord(twisted_vec)) * C0; hyperpoint h = eumove(to_coord(eu.twisted_vec)) * C0;
while(true) { while(true) {
int dsx = dscalar(coo, twisted_vec); int dsx = dscalar(coo, eu.twisted_vec);
if(dsx >= dsc) coo = coo - twisted_vec; if(dsx >= dsc) coo = coo - eu.twisted_vec;
else if (dsx < 0) coo = coo + twisted_vec; else if (dsx < 0) coo = coo + eu.twisted_vec;
else break; else break;
M = M * spintox(h) * MirrorY * rspintox(h); M = M * spintox(h) * MirrorY * rspintox(h);
auto s = ort * dscalar(d0, ort) * 2; auto s = ort * dscalar(d0, ort) * 2;
@ -638,12 +673,12 @@ EX namespace euclid3 {
coo = coo - s; coo = coo - s;
mirr = !mirr; mirr = !mirr;
} }
if(ortho_vec != gp::loc{0,0}) { if(eu.ortho_vec != gp::loc{0,0}) {
int osc = dscalar(ortho_vec, ortho_vec); int osc = dscalar(eu.ortho_vec, eu.ortho_vec);
while(true) { while(true) {
int dsx = dscalar(coo, ortho_vec); int dsx = dscalar(coo, eu.ortho_vec);
if(dsx >= osc) coo = coo - ortho_vec; if(dsx >= osc) coo = coo - eu.ortho_vec;
else if(dsx < 0) coo = coo + ortho_vec; else if(dsx < 0) coo = coo + eu.ortho_vec;
else break; else break;
} }
} }
@ -653,37 +688,31 @@ EX namespace euclid3 {
} }
coord canonicalize(coord x) { coord canonicalize(coord x) {
if(twisted) { 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); return twist(x, dummy, M, dm);
} }
if(infinite_dims == WDIM) return x; if(eu.infinite_dims == WDIM) return x;
if(infinite_dims == WDIM-1) { if(eu.infinite_dims == WDIM-1) {
while(celldistance(x + optimal_axes[0]) <= celldistance(x)) x += optimal_axes[0]; auto& o = eu.optimal_axes;
while(celldistance(x - optimal_axes[0]) < celldistance(x)) x -= optimal_axes[0]; while(celldistance(x + o[0]) <= celldistance(x)) x += o[0];
while(celldistance(x - o[0]) < celldistance(x)) x -= o[0];
return x; return x;
} }
auto cat = compute_cat(x); return eu.canonical.get(x);
auto& st = cubemap()->shifttable;
while(!canonical_hash.count(cat)) {
if(canonical_index == isize(canonical_seq)) throw hr_exception();
auto v = canonical_seq[canonical_index++];
for(auto s: st) add_canonical(v + s);
}
return canonical_seq[canonical_hash[cat]];
} }
EX void prepare_torus3() { EX void prepare_torus3() {
T_edit = T0; eu_edit = eu_input;
twisted_edit = twisted0;
} }
EX void show_fundamental() { EX void show_fundamental() {
initquickqueue(); initquickqueue();
transmatrix M = ggmatrix(cwt.at); transmatrix M = ggmatrix(cwt.at);
hyperpoint h0 = M*C0; hyperpoint h0 = M*C0;
auto& T_edit = eu_edit.user_axes;
hyperpoint ha = M*(eumove(T_edit[0]) * C0 - C0) / 2; hyperpoint ha = M*(eumove(T_edit[0]) * C0 - C0) / 2;
hyperpoint hb = M*(eumove(T_edit[1]) * C0 - C0) / 2; hyperpoint hb = M*(eumove(T_edit[1]) * C0 - C0) / 2;
if(WDIM == 3) { if(WDIM == 3) {
@ -704,12 +733,8 @@ EX namespace euclid3 {
quickqueue(); quickqueue();
} }
#if HDR intmatrix on_periods(gp::loc a, gp::loc b) {
typedef pair<euclid3::intmatrix, int> torus_config; intmatrix res;
#endif
euclid3::intmatrix on_periods(gp::loc a, gp::loc b) {
euclid3::intmatrix res;
for(int i=0; i<3; i++) for(int j=0; j<3; j++) res[i][j] = 0; for(int i=0; i<3; i++) for(int j=0; j<3; j++) res[i][j] = 0;
res[0][0] = a.first; res[0][0] = a.first;
res[0][1] = a.second; res[0][1] = a.second;
@ -720,24 +745,23 @@ EX namespace euclid3 {
} }
torus_config single_row_torus(int qty, int dy) { torus_config single_row_torus(int qty, int dy) {
return { on_periods(gp::loc{dy, -1}, gp::loc{qty, 0}), false }; return { on_periods(gp::loc{dy, -1}, gp::loc{qty, 0}), 0 };
} }
torus_config regular_torus(gp::loc p) { torus_config regular_torus(gp::loc p) {
return { on_periods(p, gp::loc(0,1) * p), false }; return { on_periods(p, gp::loc(0,1) * p), 0 };
} }
EX torus_config rectangular_torus(int x, int y, bool klein) { EX torus_config rectangular_torus(int x, int y, bool klein) {
if(S3 == 3) y /= 2; if(S3 == 3) y /= 2;
return { on_periods(euclid3::ort1() * gp::loc(y,0), gp::loc(x,0)), klein?8:0 }; return { on_periods(ort1() * gp::loc(y,0), gp::loc(x,0)), klein?8:0 };
} }
void torus_config_option(string name, char key, torus_config tc) { void torus_config_option(string name, char key, torus_config tc) {
dialog::addBoolItem(name, make_pair(T_edit, twisted_edit) == tc && PURE, key); dialog::addBoolItem(name, eu_edit.user_axes == tc.user_axes && eu_edit.twisted == tc.twisted && PURE, key);
dialog::add_action([tc] { dialog::add_action([tc] {
stop_game(); stop_game();
tie(euclid3::T0, euclid3::twisted0) = tc; eu_input = eu_edit = tc;
tie(T_edit, twisted_edit) = tc;
set_variation(eVariation::pure); set_variation(eVariation::pure);
start_game(); start_game();
}); });
@ -745,6 +769,8 @@ EX namespace euclid3 {
EX void show_torus3() { EX void show_torus3() {
int dim = WDIM; int dim = WDIM;
auto& T_edit = eu_edit.user_axes;
auto& twisted_edit = eu_edit.twisted;
cmode = sm::SIDE | sm::MAYDARK | sm::TORUSCONFIG; cmode = sm::SIDE | sm::MAYDARK | sm::TORUSCONFIG;
gamescreen(1); gamescreen(1);
dialog::init(XLAT("Euclidean quotient spaces")); dialog::init(XLAT("Euclidean quotient spaces"));
@ -806,8 +832,8 @@ EX namespace euclid3 {
dialog::add_action([] { twisted_edit ^= 4; }); dialog::add_action([] { twisted_edit ^= 4; });
} }
dialog::addBreak(50); dialog::addBreak(50);
torus_config_option(XLAT("third-turn space"), 'A', {make_third_turn(2,0,2), 16}); torus_config_option(XLAT("third-turn space"), 'A', make_third_turn(2,0,2));
torus_config_option(XLAT("quarter-turn space"), 'B', {make_quarter_turn(2, 0, 2), 5}); torus_config_option(XLAT("quarter-turn space"), 'B', make_quarter_turn(2, 0, 2));
} }
else { else {
if(T_edit[1][0] == 0 && T_edit[1][1] == 0) if(T_edit[1][0] == 0 && T_edit[1][1] == 0)
@ -855,8 +881,7 @@ EX namespace euclid3 {
dialog::add_action([g] { dialog::add_action([g] {
stop_game(); stop_game();
set_geometry(g); set_geometry(g);
T0 = T_edit; eu_input = eu_edit;
twisted0 = twisted_edit;
start_game(); start_game();
}); });
if(dim == 2) break; if(dim == 2) break;
@ -873,7 +898,7 @@ EX namespace euclid3 {
char ch = 'a' + i * 3 + j; char ch = 'a' + i * 3 + j;
if(displayfr(dialog::dcenter + dialog::dfspace * 4 * (j-(dim-1.)/2), v.position, 2, dialog::dfsize, its(T_edit[j][i]), 0xFFFFFF, 8)) if(displayfr(dialog::dcenter + dialog::dfspace * 4 * (j-(dim-1.)/2), v.position, 2, dialog::dfsize, its(T_edit[j][i]), 0xFFFFFF, 8))
getcstat = ch; getcstat = ch;
dialog::add_key_action(ch, [=] { dialog::add_key_action(ch, [&T_edit, i, j] {
dialog::editNumber(T_edit[j][i], -10, +10, 1, 0, "", XLAT( dialog::editNumber(T_edit[j][i], -10, +10, 1, 0, "", XLAT(
"This matrix lets you play on the quotient spaces of three-dimensional. " "This matrix lets you play on the quotient spaces of three-dimensional. "
"Euclidean space. Every column specifies a translation vector which " "Euclidean space. Every column specifies a translation vector which "
@ -903,6 +928,7 @@ EX namespace euclid3 {
else if(argis("-t3")) { else if(argis("-t3")) {
PHASEFROM(2); PHASEFROM(2);
stop_game(); stop_game();
auto& T0 = eu_input.user_axes;
for(int i=0; i<3; i++) for(int i=0; i<3; i++)
for(int j=0; j<3; j++) { for(int j=0; j<3; j++) {
shift(); T0[i][j] = argi(); shift(); T0[i][j] = argi();
@ -912,11 +938,12 @@ EX namespace euclid3 {
else if(argis("-t2")) { else if(argis("-t2")) {
PHASEFROM(2); PHASEFROM(2);
stop_game(); stop_game();
auto& T0 = eu_input.user_axes;
for(int i=0; i<2; i++) for(int i=0; i<2; i++)
for(int j=0; j<2; j++) { for(int j=0; j<2; j++) {
shift(); T0[i][j] = argi(); shift(); T0[i][j] = argi();
} }
shift(); twisted0 = argi(); shift(); eu_input.twisted = argi();
build_torus3(); build_torus3();
} }
else if(argis("-twistthird")) { else if(argis("-twistthird")) {
@ -925,20 +952,20 @@ EX namespace euclid3 {
shift(); int a = argi(); shift(); int a = argi();
shift(); int b = argi(); shift(); int b = argi();
shift(); int c = argi(); shift(); int c = argi();
T0 = make_third_turn(a, b, c); eu_input = make_third_turn(a, b, c);
twisted0 = 16;
build_torus3(); build_torus3();
} }
else if(argis("-twist3")) { else if(argis("-twist3")) {
PHASEFROM(2); PHASEFROM(2);
stop_game(); stop_game();
auto& T0 = eu_input.user_axes;
for(int i=0; i<3; i++) for(int i=0; i<3; i++)
for(int j=0; j<3; j++) T0[i][j] = 0; for(int j=0; j<3; j++) T0[i][j] = 0;
for(int i=0; i<3; i++) { for(int i=0; i<3; i++) {
shift(); T0[i][i] = argi(); shift(); T0[i][i] = argi();
} }
shift(); twisted0 = argi(); shift(); eu_input.twisted = argi();
build_torus3(); build_torus3();
} }
else if(argis("-twisttest")) { else if(argis("-twisttest")) {
@ -967,7 +994,6 @@ EX namespace euclid3 {
auto euhook = addHook(hooks_args, 100, euArgs); auto euhook = addHook(hooks_args, 100, euArgs);
#endif #endif
EX }
EX int dscalar(gp::loc e1, gp::loc e2) { EX int dscalar(gp::loc e1, gp::loc e2) {
return 2 * (e1.first * e2.first + e1.second*e2.second) + (S3 == 3 ? e1.first*e2.second + e2.first * e1.second : 0); return 2 * (e1.first * e2.first + e1.second*e2.second) + (S3 == 3 ? e1.first*e2.second + e2.first * e1.second : 0);
@ -979,8 +1005,8 @@ EX int dcross(gp::loc e1, gp::loc e2) {
return e1.first * e2.second - e1.second*e2.first; return e1.first * e2.second - e1.second*e2.first;
} }
EX gp::loc euc2_coordinates(cell *c) { EX gp::loc full_coords2(cell *c) {
auto ans = euclid3::eucmap()->ispacemap[c->master]; auto ans = eucmap()->ispacemap[c->master];
if(BITRUNCATED) if(BITRUNCATED)
return to_loc(ans) * gp::loc(1,1) + (c == c->master->c7 ? gp::loc(0,0) : gp::eudir((c->c.spin(0)+4)%6)); return to_loc(ans) * gp::loc(1,1) + (c == c->master->c7 ? gp::loc(0,0) : gp::eudir((c->c.spin(0)+4)%6));
if(GOLDBERG) { if(GOLDBERG) {
@ -993,7 +1019,7 @@ EX gp::loc euc2_coordinates(cell *c) {
} }
/** this is slow, but we use it only for small p's */ /** this is slow, but we use it only for small p's */
EX cell* at_euc2_coordinates(gp::loc p) { EX cell* at(gp::loc p) {
cellwalker cw(currentmap->gamestart()); cellwalker cw(currentmap->gamestart());
while(p.first--) cw += revstep; while(p.first--) cw += revstep;
cw ++; cw ++;
@ -1001,15 +1027,15 @@ EX cell* at_euc2_coordinates(gp::loc p) {
return cw.at; return cw.at;
} }
EX euclid3::coord to_coord(gp::loc p) { return euclid3::coord(p.first, p.second, 0); } EX coord to_coord(gp::loc p) { return coord(p.first, p.second, 0); }
EX gp::loc sdxy() { return to_loc(euclid3::T[1]) * gp::univ_param(); } EX gp::loc sdxy() { return to_loc(eu.user_axes[1]) * gp::univ_param(); }
EX pair<bool, string> coord_display(const transmatrix& V, cell *c) { EX pair<bool, string> coord_display(const transmatrix& V, cell *c) {
if(c != c->master->c7) return {false, ""}; if(c != c->master->c7) return {false, ""};
hyperpoint hx = eumove(euclid3::main_axes[0]) * C0; hyperpoint hx = eumove(main_axes[0]) * C0;
hyperpoint hy = eumove(euclid3::main_axes[1]) * C0; hyperpoint hy = eumove(main_axes[1]) * C0;
hyperpoint hz = WDIM == 2 ? C0 : eumove(euclid3::main_axes[2]) * C0; hyperpoint hz = WDIM == 2 ? C0 : eumove(main_axes[2]) * C0;
hyperpoint h = kz(inverse(build_matrix(hx, hy, hz, C03)) * inverse(ggmatrix(cwt.at->master->c7)) * V * C0); hyperpoint h = kz(inverse(build_matrix(hx, hy, hz, C03)) * inverse(ggmatrix(cwt.at->master->c7)) * V * C0);
if(WDIM == 3) if(WDIM == 3)
@ -1018,11 +1044,11 @@ EX pair<bool, string> coord_display(const transmatrix& V, cell *c) {
return {true, fts(h[0]) + "," + fts(h[1]) }; return {true, fts(h[0]) + "," + fts(h[1]) };
} }
EX gp::loc to_loc(const euclid3::coord& v) { return gp::loc(v[0], v[1]); } EX gp::loc to_loc(const coord& v) { return gp::loc(v[0], v[1]); }
EX map<gp::loc, cdata>& get_cdata() { return euclid3::eucmap()->eucdata; } EX map<gp::loc, cdata>& get_cdata() { return eucmap()->eucdata; }
EX transmatrix eumove(euclid3::coord co) { EX transmatrix eumove(coord co) {
const double q3 = sqrt(double(3)); const double q3 = sqrt(double(3));
if(WDIM == 3) { if(WDIM == 3) {
return eupush3(co[0], co[1], co[2]); return eupush3(co[0], co[1], co[2]);
@ -1039,6 +1065,8 @@ EX transmatrix eumove(euclid3::coord co) {
return Mat; return Mat;
} }
EX transmatrix eumove(gp::loc co) { return eumove(to_coord(co)); }
EX bool chiral(gp::loc g) { EX bool chiral(gp::loc g) {
int x = g.first; int x = g.first;
int y = g.second; int y = g.second;
@ -1052,9 +1080,9 @@ EX bool chiral(gp::loc g) {
} }
EX void twist_once(gp::loc coo) { EX void twist_once(gp::loc coo) {
coo = coo - euclid3::twisted_vec * gp::univ_param(); coo = coo - eu.twisted_vec * gp::univ_param();
if(euclid3::twisted&8) { if(eu.twisted&8) {
gp::loc ort = euclid3::ort1() * euclid3::twisted_vec * gp::univ_param(); gp::loc ort = ort1() * eu.twisted_vec * gp::univ_param();
auto s = ort * dscalar(coo, ort) * 2; auto s = ort * dscalar(coo, ort) * 2;
auto v = dscalar(ort, ort); auto v = dscalar(ort, ort);
s.first /= v; s.first /= v;
@ -1063,7 +1091,7 @@ EX void twist_once(gp::loc coo) {
} }
} }
EX int eudist(int sx, int sy, bool reduce IS(true)) { EX int dist(int sx, int sy, bool reduce IS(true)) {
int z0 = abs(sx); int z0 = abs(sx);
int z1 = abs(sy); int z1 = abs(sy);
if(a4 && BITRUNCATED) if(a4 && BITRUNCATED)
@ -1073,28 +1101,36 @@ EX int eudist(int sx, int sy, bool reduce IS(true)) {
return max(max(z0,z1), z2); return max(max(z0,z1), z2);
} }
EX int eudist(gp::loc a, gp::loc b) { EX int dist(gp::loc a, gp::loc b) {
return eudist(a.first-b.first, a.second-b.second, (a.first ^ a.second)&1); return dist(a.first-b.first, a.second-b.second, (a.first ^ a.second)&1);
} }
EX int cyldist(gp::loc a, gp::loc b) { EX int cyldist(gp::loc a, gp::loc b) {
a = to_loc(euclid3::canonicalize(to_coord(a))); a = to_loc(canonicalize(to_coord(a)));
b = to_loc(euclid3::canonicalize(to_coord(b))); b = to_loc(canonicalize(to_coord(b)));
if(!quotient) return eudist(a, b); if(!quotient) return dist(a, b);
int best = 0; int best = 0;
for(int sa=0; sa<16; sa++) { for(int sa=0; sa<16; sa++) {
auto _a = a, _b = b; auto _a = a, _b = b;
if(sa&1) twist_once(_a); if(sa&1) twist_once(_a);
if(sa&2) twist_once(_b); if(sa&2) twist_once(_b);
if(sa&4) _a = _a + euclid3::ortho_vec * gp::univ_param(); if(sa&4) _a = _a + eu.ortho_vec * gp::univ_param();
if(sa&8) _b = _b + euclid3::ortho_vec * gp::univ_param(); if(sa&8) _b = _b + eu.ortho_vec * gp::univ_param();
int val = eudist(_a, _b); int val = dist(_a, _b);
if(sa == 0 || val < best) best = val; if(sa == 0 || val < best) best = val;
} }
return best; return best;
} }
EX }
#if HDR
namespace euclid3 { using namespace euc; }
#endif
EX gp::loc euc2_coordinates(cell *c) { return euc::full_coords2(c); }
} }

View File

@ -585,7 +585,7 @@ EX void showEuclideanMenu() {
} }
if(euclid && bounded) { if(euclid && bounded) {
worldsize = euclid3::det; worldsize = euclid3::eu.det;
if(BITRUNCATED) worldsize *= (a4 ? 2 : 3); if(BITRUNCATED) worldsize *= (a4 ? 2 : 3);
if(GOLDBERG) worldsize *= cgi.gpdata->area; if(GOLDBERG) worldsize *= cgi.gpdata->area;
if(IRREGULAR) worldsize *= isize(irr::cells) / isize(irr::cells_of_heptagon); if(IRREGULAR) worldsize *= isize(irr::cells) / isize(irr::cells_of_heptagon);

View File

@ -69,7 +69,7 @@ EX namespace gp {
} }
EX int length(loc p) { EX int length(loc p) {
return eudist(p.first, p.second); return euc::dist(p.first, p.second);
} }
#if CAP_GP #if CAP_GP

View File

@ -121,8 +121,7 @@ string status[5];
EX hrmap *base; EX hrmap *base;
EX euclid3::intmatrix base_periods; EX euc::torus_config_full base_config;
EX int base_twisted;
bool gridmaking; bool gridmaking;
@ -1031,8 +1030,7 @@ EX void visual_creator() {
start_game(); start_game();
if(base) delete base; if(base) delete base;
base = currentmap; base = currentmap;
base_periods = euclid3::T0; base_config = euc::eu;
base_twisted = euclid3::twisted0;
drawthemap(); drawthemap();
cellcount = int(isize(base->allcells()) * density + .5); cellcount = int(isize(base->allcells()) * density + .5);
pushScreen(show_gridmaker); pushScreen(show_gridmaker);

View File

@ -1286,10 +1286,10 @@ EX void giantLandSwitch(cell *c, int d, cell *from) {
if(fargen) { if(fargen) {
if(euclid && smallbounded && WDIM == 2) { if(euclid && smallbounded && WDIM == 2) {
auto s = sdxy(); auto s = euc::sdxy();
gp::loc st {s.first/3, s.second/3}; gp::loc st {s.first/3, s.second/3};
if(c == at_euc2_coordinates(st)) c->wall = waCharged; if(c == euc::at(st)) c->wall = waCharged;
if(c == at_euc2_coordinates(s-st)) c->wall = waGrounded; if(c == euc::at(s-st)) c->wall = waGrounded;
} }
else if(euclid && WDIM == 2) { else if(euclid && WDIM == 2) {
auto co = euc2_coordinates(c); auto co = euc2_coordinates(c);

View File

@ -1126,10 +1126,10 @@ EX land_validity_t& land_validity(eLand l) {
if(sol && l == laCamelot) if(sol && l == laCamelot)
return not_implemented; return not_implemented;
if(euclid && quotient && !bounded && l == laCrossroads && sdxy().second == -2 * sdxy().first) if(euclid && quotient && !bounded && l == laCrossroads && euc::sdxy().second == -2 * euc::sdxy().first)
return full_game; return full_game;
if(euclid && quotient && !bounded && l == laCrossroads4 && sdxy().second == 0) if(euclid && quotient && !bounded && l == laCrossroads4 && euc::sdxy().second == 0)
return full_game; return full_game;
// highlight Zebra-based lands on Zebra Quotient! // highlight Zebra-based lands on Zebra Quotient!

View File

@ -168,8 +168,8 @@ namespace mapstream {
if(binarytiling && VERNUM_HEX >= 0xA80C) if(binarytiling && VERNUM_HEX >= 0xA80C)
f.write(vid.binary_width); f.write(vid.binary_width);
if(euclid && !penrose && !archimedean) { if(euclid && !penrose && !archimedean) {
f.write(euclid3::T0); f.write(euc::eu_input.user_axes);
f.write(euclid3::twisted); f.write(euc::eu_input.twisted);
} }
} }
@ -254,8 +254,8 @@ namespace mapstream {
if(binarytiling && VERNUM_HEX >= 0xA80C) if(binarytiling && VERNUM_HEX >= 0xA80C)
f.read(vid.binary_width); f.read(vid.binary_width);
if(euclid && !penrose && !archimedean && VERNUM_HEX >= 0xA80D) { if(euclid && !penrose && !archimedean && VERNUM_HEX >= 0xA80D) {
f.read(euclid3::T0); f.read(euc::eu_input.user_axes);
f.read(euclid3::twisted); f.read(euc::eu_input.twisted);
} }
} }

View File

@ -192,7 +192,7 @@ EX namespace models {
if(euclid) { if(euclid) {
euclidean_spin = pispin * inverse(cview() * master_relative(centerover, true)); euclidean_spin = pispin * inverse(cview() * master_relative(centerover, true));
euclidean_spin = gpushxto0(euclidean_spin * C0) * euclidean_spin; euclidean_spin = gpushxto0(euclidean_spin * C0) * euclidean_spin;
hyperpoint h = inverse(euclidean_spin) * (C0 + (eumove(to_coord(gp::loc{1,0}))*C0 - C0) * spiral_x + (eumove(to_coord(gp::loc{0,1}))*C0 - C0) * spiral_y); hyperpoint h = inverse(euclidean_spin) * (C0 + (euc::eumove(gp::loc{1,0})*C0 - C0) * spiral_x + (euc::eumove(gp::loc{0,1})*C0 - C0) * spiral_y);
spiral_multiplier = cld(0, 2 * M_PI) / cld(h[0], h[1]); spiral_multiplier = cld(0, 2 * M_PI) / cld(h[0], h[1]);
} }
@ -267,13 +267,13 @@ 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 = euclid3::canonicalize(to_coord(gp::loc{x, y})); auto zero = euc::canonicalize(euc::to_coord(gp::loc{x, y}));
if(zero == euclid3::euzero) if(zero == euclid3::euzero)
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) {
ld d1 = hdist0(tC0(eumove(to_coord(p1)))); ld d1 = hdist0(tC0(euc::eumove(p1)));
ld d2 = hdist0(tC0(eumove(to_coord(p2)))); ld d2 = hdist0(tC0(euc::eumove(p2)));
if(d1 < d2 - 1e-6) return true; if(d1 < d2 - 1e-6) return true;
if(d1 > d2 + 1e-6) return false; if(d1 > d2 + 1e-6) return false;
return p1 < p2; return p1 < p2;

View File

@ -2443,12 +2443,12 @@ EX namespace linepatterns {
case patZebraTriangles: case patZebraTriangles:
if(euclid6) { if(euclid6) {
if(c != c->master->c7 || patterns::sevenval(c)) break; if(c != c->master->c7 || patterns::sevenval(c)) break;
gridline(V, C0, tC0(eumove(to_coord({-1, +3}))), col, 3 + vid.linequality); gridline(V, C0, tC0(euc::eumove(gp::loc(-1, +3))), col, 3 + vid.linequality);
gridline(V, C0, tC0(eumove(to_coord({-3, +2}))), col, 3 + vid.linequality); gridline(V, C0, tC0(euc::eumove(gp::loc(-3, +2))), col, 3 + vid.linequality);
gridline(V, C0, tC0(eumove(to_coord({-2, -1}))), col, 3 + vid.linequality); gridline(V, C0, tC0(euc::eumove(gp::loc(-2, -1))), col, 3 + vid.linequality);
gridline(V, C0, tC0(eumove(to_coord({+1, -3}))), col, 3 + vid.linequality); gridline(V, C0, tC0(euc::eumove(gp::loc(+1, -3))), col, 3 + vid.linequality);
gridline(V, C0, tC0(eumove(to_coord({+3, -2}))), col, 3 + vid.linequality); gridline(V, C0, tC0(euc::eumove(gp::loc(+3, -2))), col, 3 + vid.linequality);
gridline(V, C0, tC0(eumove(to_coord({+2, +1}))), col, 3 + vid.linequality); gridline(V, C0, tC0(euc::eumove(gp::loc(+2, +1))), col, 3 + vid.linequality);
break; break;
} }
if(zebra40(c) / 4 == 10) { if(zebra40(c) / 4 == 10) {

View File

@ -1095,7 +1095,7 @@ void race_projection() {
add_thurston_race(XLAT("stretched Solv"), [] { set_geometry(gSolN); solnihv::solrange_xy = 10; solnihv::solrange_z = 3; vid.texture_step = 4; }); add_thurston_race(XLAT("stretched Solv"), [] { set_geometry(gSolN); solnihv::solrange_xy = 10; solnihv::solrange_z = 3; vid.texture_step = 4; });
add_thurston_race(XLAT("periodic Solv"), [] { stop_game(); solnihv::solrange_xy = 5; solnihv::solrange_z = 2; asonov::period_xy = 8; asonov::period_z = 0; asonov::set_flags(); set_geometry(gArnoldCat); }); add_thurston_race(XLAT("periodic Solv"), [] { stop_game(); solnihv::solrange_xy = 5; solnihv::solrange_z = 2; asonov::period_xy = 8; asonov::period_z = 0; asonov::set_flags(); set_geometry(gArnoldCat); });
add_thurston_race(XLAT("hyperbolic crystal"), [] { set_geometry(gCrystal344); vid.texture_step = 4; }); add_thurston_race(XLAT("hyperbolic crystal"), [] { set_geometry(gCrystal344); vid.texture_step = 4; });
add_thurston_race(XLAT("torus x E"), [] { stop_game(); euclid3::set_torus3(4, 4, 0); set_geometry(gCubeTiling); }); add_thurston_race(XLAT("torus x E"), [] { stop_game(); euc::eu_input = euc::torus3(4, 4, 0); set_geometry(gCubeTiling); });
add_thurston_race(XLAT("hyperbolic regular"), [] { set_geometry(gSpace534); }); add_thurston_race(XLAT("hyperbolic regular"), [] { set_geometry(gSpace534); });
add_thurston_race(XLAT("S2xE regular"), [] { set_geometry(gSphere); set_variation(eVariation::pure); set_geometry(gProduct); }); add_thurston_race(XLAT("S2xE regular"), [] { set_geometry(gSphere); set_variation(eVariation::pure); set_geometry(gProduct); });
add_thurston_race(XLAT("H2xE regular"), [] { set_geometry(gNormal); set_variation(eVariation::pure); set_geometry(gProduct); }); add_thurston_race(XLAT("H2xE regular"), [] { set_geometry(gNormal); set_variation(eVariation::pure); set_geometry(gProduct); });

12
rug.cpp
View File

@ -253,7 +253,7 @@ EX rugpoint *addRugpoint(hyperpoint h, double dist) {
m->valid = false; m->valid = false;
if(euclid && quotient && !bounded) { if(euclid && quotient && !bounded) {
hyperpoint h1 = inverse(models::euclidean_spin) * eumove(euclid3::T0[1]) * C0; hyperpoint h1 = inverse(models::euclidean_spin) * eumove(euc::eu.user_axes[1]) * C0;
h1 /= sqhypot_d(2, h1); h1 /= sqhypot_d(2, h1);
if(nonorientable) h1 /= 2; if(nonorientable) h1 /= 2;
m->valid = good_shape = true; m->valid = good_shape = true;
@ -432,11 +432,11 @@ EX void buildTorusRug() {
calcparam_rug(); calcparam_rug();
models::configure(); models::configure();
auto p1 = to_loc(euclid3::T0[0]); auto p1 = to_loc(euc::eu.user_axes[0]);
auto p2 = to_loc(euclid3::T0[1]); auto p2 = to_loc(euc::eu.user_axes[1]);
hyperpoint xh = eumove(to_coord(p1))*C0-C0; hyperpoint xh = euc::eumove(p1)*C0-C0;
hyperpoint yh = eumove(to_coord(p2))*C0-C0; hyperpoint yh = euc::eumove(p2)*C0-C0;
if(nonorientable) yh *= 2; if(nonorientable) yh *= 2;
bool flipped = sqhypot_d(2, xh) < sqhypot_d(2, yh); bool flipped = sqhypot_d(2, xh) < sqhypot_d(2, yh);
@ -597,7 +597,7 @@ EX void buildRug() {
for(int j=0; j<c->type; j++) addTriangle(v, p[j], p[(j+1) % c->type]); for(int j=0; j<c->type; j++) addTriangle(v, p[j], p[(j+1) % c->type]);
if((euclid && quotient) && nonorientable) { if((euclid && quotient) && nonorientable) {
transmatrix T = ggmatrix(c) * eumove(euclid3::T0[1]); transmatrix T = ggmatrix(c) * eumove(euc::eu.user_axes[1]);
rugpoint *Tv = addRugpoint(T * C0, 0); rugpoint *Tv = addRugpoint(T * C0, 0);
for(int j=0; j<c->type; j++) p[j] = findOrAddRugpoint(T * get_corner_position(c, j), v->dist); for(int j=0; j<c->type; j++) p[j] = findOrAddRugpoint(T * get_corner_position(c, j), v->dist);
for(int j=0; j<c->type; j++) addTriangle(Tv, p[j], p[(j+1) % c->type]); for(int j=0; j<c->type; j++) addTriangle(Tv, p[j], p[(j+1) % c->type]);

View File

@ -242,7 +242,7 @@ EX void initgame() {
if(gamegen_failure) return; if(gamegen_failure) return;
if(euclid && specialland == laPrincessQuest) { if(euclid && specialland == laPrincessQuest) {
cell *c = at_euc2_coordinates({EPX, EPY}); cell *c = euc::at(princess::coords());
princess::generating = true; princess::generating = true;
c->land = laPalace; c->land = laPalace;
setdist(c, 7 - getDistLimit() - genrange_bonus, NULL); setdist(c, 7 - getDistLimit() - genrange_bonus, NULL);