2019-03-02 23:43:31 +00:00
|
|
|
// Hyperbolic Rogue -- regular honeycombs
|
|
|
|
// Copyright (C) 2011-2019 Zeno Rogue, see 'hyper.cpp' for details
|
|
|
|
|
2019-08-10 11:43:24 +00:00
|
|
|
/** \file reg3.cpp
|
|
|
|
* \brief regular honeycombs
|
|
|
|
*
|
|
|
|
* works with spherical and hyperbolic ones -- Euclidean cubic tiling implemented in euclid.cpp
|
|
|
|
* includes non-quotient spaces as well as field quotient and elliptic spaces
|
2019-12-14 11:05:01 +00:00
|
|
|
* hyperbolic honeycombs rely on bt:: to deal with floating point errors (just like archimedean)
|
2019-08-10 11:43:24 +00:00
|
|
|
*/
|
|
|
|
|
2019-09-05 07:15:40 +00:00
|
|
|
#include "hyper.h"
|
2019-03-02 23:43:31 +00:00
|
|
|
namespace hr {
|
|
|
|
#if MAXMDIM >= 4
|
2019-08-17 21:30:27 +00:00
|
|
|
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief regular three-dimensional tessellations */
|
2019-08-09 20:37:11 +00:00
|
|
|
EX namespace reg3 {
|
|
|
|
|
|
|
|
#if HDR
|
|
|
|
inline short& altdist(heptagon *h) { return h->emeraldval; }
|
|
|
|
#endif
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-07-04 22:45:25 +00:00
|
|
|
EX int extra_verification;
|
|
|
|
|
2020-05-27 23:50:00 +00:00
|
|
|
EX bool ultra_mirror_on;
|
|
|
|
|
|
|
|
EX bool ultra_mirror_in() { return (cgflags & qULTRA) && ultra_mirror_on; }
|
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
EX bool in() {
|
2020-05-15 09:46:26 +00:00
|
|
|
if(fake::in()) return FPIU(in());
|
2020-06-03 09:48:07 +00:00
|
|
|
return WDIM == 3 && !euclid && !bt::in() && !nonisotropic && !hybri && !kite::in();
|
2020-04-05 08:53:34 +00:00
|
|
|
}
|
2020-01-06 19:53:09 +00:00
|
|
|
|
2020-05-27 23:50:00 +00:00
|
|
|
EX void compute_ultra() {
|
|
|
|
cgi.ultra_mirror_part = .99;
|
|
|
|
cgi.ultra_material_part = .99;
|
|
|
|
|
2020-07-03 13:07:59 +00:00
|
|
|
cgi.ultra_mirrors.clear();
|
|
|
|
|
2020-05-27 23:50:00 +00:00
|
|
|
if(cgflags & qULTRA) {
|
2020-07-03 13:07:59 +00:00
|
|
|
|
|
|
|
for(auto& v: cgi.vertices_only) {
|
|
|
|
|
|
|
|
hyperpoint nei;
|
|
|
|
|
|
|
|
for(int i=0; i<isize(cgi.cellshape); i++)
|
2021-03-25 10:12:58 +00:00
|
|
|
for(int j=0; j<isize(cgi.cellshape[i]); j++)
|
|
|
|
if(sqhypot_d(WDIM, cgi.cellshape[i][j]-v) < 1e-6)
|
|
|
|
nei = cgi.cellshape[i][j?j-1:j+1];
|
2020-07-03 13:07:59 +00:00
|
|
|
|
|
|
|
transmatrix T = spintox(v);
|
|
|
|
hyperpoint a = T * v;
|
|
|
|
hyperpoint b = T * nei;
|
|
|
|
ld f0 = 0.5;
|
|
|
|
ld f1 = binsearch(0.5, 1, [&] (ld d) {
|
|
|
|
hyperpoint c = lerp(b, a, d);
|
|
|
|
if(debugflags & DF_GEOM)
|
|
|
|
println(hlog, "d=", d, " c= ", c, " material = ", material(c));
|
|
|
|
return material(c) <= 0;
|
|
|
|
});
|
|
|
|
cgi.ultra_material_part = f1;
|
|
|
|
auto f = [&] (ld d) {
|
|
|
|
hyperpoint c = lerp(b, a, d);
|
|
|
|
c = normalize(c);
|
|
|
|
return c[1] * c[1] + c[2] * c[2];
|
|
|
|
};
|
|
|
|
for(int it=0; it<100; it++) {
|
|
|
|
ld fa = (f0*2+f1) / 3;
|
|
|
|
ld fb = (f0*1+f1*2) / 3;
|
|
|
|
if(debugflags & DF_GEOM)
|
|
|
|
println(hlog, "f(", fa, ") = ", f(fa), " f(", fb, ") = ", f(fb));
|
|
|
|
if(f(fa) > f(fb)) f0 = fa;
|
|
|
|
else f1 = fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
cgi.ultra_mirror_part = f0;
|
|
|
|
|
|
|
|
hyperpoint c = lerp(b, a, f0);
|
2020-05-27 23:50:00 +00:00
|
|
|
c = normalize(c);
|
2020-07-03 13:07:59 +00:00
|
|
|
c[1] = c[2] = 0;
|
|
|
|
c = normalize(c);
|
|
|
|
cgi.ultra_mirror_dist = hdist0(c);
|
|
|
|
|
|
|
|
if(cgi.ultra_mirror_part >= 1-1e-6) continue;
|
|
|
|
|
|
|
|
cgi.ultra_mirrors.push_back(rspintox(v) * xpush(cgi.ultra_mirror_dist*2) * MirrorX * spintox(v));
|
2020-05-27 23:50:00 +00:00
|
|
|
}
|
2020-07-03 13:07:59 +00:00
|
|
|
}
|
2020-05-27 23:50:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 00:43:30 +00:00
|
|
|
EX void make_vertices_only() {
|
|
|
|
auto& vertices_only = cgi.vertices_only;
|
|
|
|
vertices_only.clear();
|
2021-03-25 10:12:58 +00:00
|
|
|
for(auto& v: cgi.cellshape)
|
|
|
|
for(hyperpoint h: v) {
|
2020-05-29 00:43:30 +00:00
|
|
|
bool found = false;
|
|
|
|
for(hyperpoint h2: vertices_only) if(hdist(h, h2) < 1e-6) found = true;
|
|
|
|
if(!found) vertices_only.push_back(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 20:37:11 +00:00
|
|
|
EX void generate() {
|
2020-05-15 09:46:26 +00:00
|
|
|
|
|
|
|
if(fake::in()) {
|
|
|
|
fake::generate();
|
|
|
|
return;
|
|
|
|
}
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
int& loop = cgi.loop;
|
|
|
|
int& face = cgi.face;
|
|
|
|
auto& spins = cgi.spins;
|
|
|
|
auto& cellshape = cgi.cellshape;
|
|
|
|
auto& adjcheck = cgi.adjcheck;
|
|
|
|
auto& dirs_adjacent = cgi.dirs_adjacent;
|
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
int& mid = cgi.schmid;
|
|
|
|
mid = 3;
|
|
|
|
|
|
|
|
face = 3;
|
2019-03-02 23:43:31 +00:00
|
|
|
if(S7 == 6) face = 4;
|
2020-05-26 22:54:15 +00:00
|
|
|
if(S7 == 8) mid = 4;
|
2019-03-02 23:43:31 +00:00
|
|
|
if(S7 == 12) face = 5;
|
2020-05-26 22:54:15 +00:00
|
|
|
if(S7 == 20) mid = 5;
|
2019-03-02 23:43:31 +00:00
|
|
|
/* icosahedron not implemented */
|
|
|
|
loop = ginf[geometry].tiling_name[5] - '0';
|
2020-05-26 22:54:15 +00:00
|
|
|
DEBB(DF_GEOM, ("face = ", face, " loop = ", loop, " S7 = ", S7));
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
ld angle_between_faces, hcrossf;
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
/* frontal face direction */
|
|
|
|
hyperpoint h0, h1, h2, h3, h012, h013;
|
|
|
|
|
|
|
|
if(1) {
|
|
|
|
dynamicval<eGeometry> dg(geometry, gSphere);
|
|
|
|
angle_between_faces = edge_of_triangle_with_angles(2*M_PI/mid, M_PI/face, M_PI/face);
|
|
|
|
|
|
|
|
h0 = xtangent(1);
|
|
|
|
h1 = cspin(0, 1, angle_between_faces) * h0;
|
|
|
|
h2 = cspin(1, 2, 2*M_PI/face) * h1;
|
|
|
|
h3 = cspin(1, 2, -2*M_PI/face) * h1;
|
|
|
|
|
|
|
|
hcrossf = edge_of_triangle_with_angles(M_PI/2, M_PI/mid, M_PI/face);
|
|
|
|
|
|
|
|
h012 = cspin(1, 2, M_PI/face) * cspin(0, 1, hcrossf) * h0;
|
|
|
|
h013 = cspin(1, 2, -M_PI/face) * cspin(0, 1, hcrossf) * h0;
|
2019-03-02 23:43:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
for(auto hx: {&h0, &h1, &h2, &h3, &h012, &h013}) (*hx)[3] = 0;
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
ld klein_scale = binsearch(0, 10, [&] (ld d) {
|
|
|
|
dynamicval<eGeometry> g(geometry, elliptic ? gCell120 : geometry);
|
|
|
|
|
|
|
|
/* center of an edge */
|
|
|
|
hyperpoint u = C0 + (h012 + h013) * d / 2;
|
2019-10-10 11:15:43 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
if(material(u) <= 0) {
|
|
|
|
println(hlog, "klein_scale = ", d, " bad");
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-10 11:15:43 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
u = normalize(u);
|
2019-10-10 11:15:43 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
hyperpoint h = C0 * face;
|
|
|
|
for(int i=0; i<face; i++) h += d * (cspin(1, 2, M_PI*2*i/face) * h012);
|
|
|
|
h = normalize(h);
|
|
|
|
|
|
|
|
hyperpoint h2 = rspintox(h) * xpush0(2 * hdist0(h));
|
|
|
|
|
|
|
|
h2 = spintox(u) * h2;
|
|
|
|
u = spintox(u) * u;
|
|
|
|
|
|
|
|
h2 = gpushxto0(u) * h2;
|
|
|
|
u = gpushxto0(u) * u;
|
|
|
|
|
|
|
|
ld x = hypot(h2[1], h2[2]);
|
|
|
|
ld y = h2[0];
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
ld loop2 = 360 / (90 + atan(y/x) / degree);
|
|
|
|
|
|
|
|
println(hlog, "d=", d, " loop2= ", loop2);
|
|
|
|
|
|
|
|
if(sphere) return loop2 < loop;
|
|
|
|
return loop2 > loop;
|
|
|
|
});
|
2019-10-10 11:15:43 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
/* precise ideal vertex */
|
|
|
|
if(klein_scale > 1-1e-5 && klein_scale < 1+1e-5) klein_scale = 1;
|
2019-10-10 11:15:43 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
/* actual vertex */
|
|
|
|
hyperpoint v2 = C0 + klein_scale * h012;
|
|
|
|
|
|
|
|
hyperpoint midface = Hypc;
|
|
|
|
for(int i=0; i<face; i++) midface += cspin(1, 2, 2*i*M_PI/face) * v2;
|
|
|
|
midface = normalize(midface);
|
|
|
|
ld between_centers = 2 * hdist0(midface);
|
|
|
|
DEBB(DF_GEOM, ("between_centers = ", between_centers));
|
2019-10-10 11:15:43 +00:00
|
|
|
|
2020-05-26 22:54:15 +00:00
|
|
|
if(S7 == 20) {
|
|
|
|
spins[0] = Id;
|
|
|
|
spins[1] = cspin(0, 1, angle_between_faces) * cspin(1, 2, M_PI);
|
|
|
|
spins[2] = spins[1] * cspin(1, 2, -2 * M_PI/face) * spins[1];
|
|
|
|
spins[3] = spins[1] * cspin(1, 2, +2 * M_PI/face) * spins[1];
|
|
|
|
for(int a=4; a<10; a++) spins[a] = cspin(1, 2, 2*M_PI/face) * spins[a-3];
|
|
|
|
for(int a=S7/2; a<S7; a++) spins[a] = spins[a-S7/2] * cspin(0, 1, M_PI);
|
|
|
|
}
|
2019-03-02 23:43:31 +00:00
|
|
|
|
|
|
|
if(S7 == 12 || S7 == 8) {
|
|
|
|
spins[0] = Id;
|
2019-10-10 11:15:43 +00:00
|
|
|
spins[1] = cspin(0, 1, angle_between_faces) * cspin(1, 2, M_PI);
|
2019-03-02 23:43:31 +00:00
|
|
|
for(int a=2; a<face+1; a++) spins[a] = cspin(1, 2, 2*M_PI*(a-1)/face) * spins[1];
|
|
|
|
for(int a=S7/2; a<S7; a++) spins[a] = cspin(0, 1, M_PI) * spins[a-S7/2];
|
2019-10-12 11:19:18 +00:00
|
|
|
if(S7 == 8) swap(spins[6], spins[7]);
|
|
|
|
if(S7 == 12) swap(spins[8], spins[11]);
|
|
|
|
if(S7 == 12) swap(spins[9], spins[10]);
|
2019-03-02 23:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(S7 == 6) {
|
|
|
|
spins[0] = Id;
|
2019-10-10 11:15:43 +00:00
|
|
|
spins[1] = cspin(0, 1, angle_between_faces) * cspin(1, 2, M_PI);
|
2019-03-02 23:43:31 +00:00
|
|
|
spins[2] = cspin(1, 2, M_PI/2) * spins[1];
|
|
|
|
for(int a=S7/2; a<S7; a++) spins[a] = spins[a-S7/2] * cspin(0, 1, M_PI);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(S7 == 4) {
|
|
|
|
spins[0] = Id;
|
2019-10-10 11:15:43 +00:00
|
|
|
spins[1] = cspin(0, 1, angle_between_faces) * cspin(1, 2, M_PI);
|
2019-03-02 23:43:31 +00:00
|
|
|
for(int a=2; a<face+1; a++) spins[a] = cspin(1, 2, 2*M_PI*(a-1)/face) * spins[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
cellshape.clear();
|
2021-03-25 10:12:58 +00:00
|
|
|
cellshape.resize(S7);
|
|
|
|
for(int a=0; a<S7; a++) {
|
|
|
|
for(int b=0; b<face; b++)
|
|
|
|
cellshape[a].push_back(spins[a] * cspin(1, 2, 2*M_PI*b/face) * v2);
|
|
|
|
}
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
cgi.adjmoves[0] = cpush(0, between_centers) * cspin(0, 2, M_PI);
|
|
|
|
for(int i=1; i<S7; i++) cgi.adjmoves[i] = spins[i] * cgi.adjmoves[0];
|
2019-03-02 23:43:31 +00:00
|
|
|
|
|
|
|
for(int a=0; a<S7; a++)
|
2020-04-05 08:53:34 +00:00
|
|
|
DEBB(DF_GEOM, ("center of ", a, " is ", tC0(cgi.adjmoves[a])));
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
DEBB(DF_GEOM, ("doublemove = ", tC0(cgi.adjmoves[0] * cgi.adjmoves[0])));
|
2019-03-10 17:37:09 +00:00
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
adjcheck = hdist(tC0(cgi.adjmoves[0]), tC0(cgi.adjmoves[1])) * 1.0001;
|
2019-03-10 17:37:09 +00:00
|
|
|
|
|
|
|
int numedges = 0;
|
|
|
|
for(int a=0; a<S7; a++) for(int b=0; b<S7; b++) {
|
2020-04-05 08:53:34 +00:00
|
|
|
dirs_adjacent[a][b] = a != b && hdist(tC0(cgi.adjmoves[a]), tC0(cgi.adjmoves[b])) < adjcheck;
|
2019-03-10 17:37:09 +00:00
|
|
|
if(dirs_adjacent[a][b]) numedges++;
|
|
|
|
}
|
2019-11-17 12:52:34 +00:00
|
|
|
DEBB(DF_GEOM, ("numedges = ", numedges));
|
2019-03-10 17:37:09 +00:00
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
if(loop == 4) cgi.strafedist = adjcheck;
|
|
|
|
else cgi.strafedist = hdist(cgi.adjmoves[0] * C0, cgi.adjmoves[1] * C0);
|
2020-05-08 19:18:47 +00:00
|
|
|
|
2020-05-09 08:41:15 +00:00
|
|
|
if(stretch::applicable()) {
|
2020-05-08 19:18:47 +00:00
|
|
|
transmatrix T = cspin(0, 2, 90 * degree);
|
|
|
|
transmatrix iT = inverse(T);
|
|
|
|
for(auto& v: cgi.adjmoves) v = T * v * iT;
|
2021-03-25 10:12:58 +00:00
|
|
|
for(auto& vv: cellshape) for(auto& v: vv) v = T * v;
|
2020-05-08 19:18:47 +00:00
|
|
|
}
|
2019-04-08 14:16:16 +00:00
|
|
|
|
2020-05-29 00:43:30 +00:00
|
|
|
make_vertices_only();
|
2020-05-27 23:50:00 +00:00
|
|
|
compute_ultra();
|
|
|
|
|
2020-05-27 23:51:28 +00:00
|
|
|
for(int a=0; a<S7; a++)
|
|
|
|
for(int b=0; b<S7; b++)
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.dirs_adjacent[a][b])
|
2020-05-27 23:51:28 +00:00
|
|
|
for(int c=0; c<S7; c++)
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.dirs_adjacent[a][c] && cgi.dirs_adjacent[b][c]) {
|
|
|
|
transmatrix t = build_matrix(tC0(cgi.adjmoves[a]), tC0(cgi.adjmoves[b]), tC0(cgi.adjmoves[c]), C0);
|
|
|
|
if(det(t) > 1e-3) cgi.next_dir[a][b] = c;
|
2020-01-06 19:53:09 +00:00
|
|
|
}
|
2019-03-02 23:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void binary_rebase(heptagon *h, const transmatrix& V) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void test();
|
2019-10-12 11:19:58 +00:00
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
#if HDR
|
2019-10-12 11:19:58 +00:00
|
|
|
struct hrmap_quotient3 : hrmap {
|
2019-03-15 12:46:23 +00:00
|
|
|
vector<heptagon*> allh;
|
2019-10-12 11:19:58 +00:00
|
|
|
vector<vector<transmatrix>> tmatrices;
|
2020-01-06 20:23:17 +00:00
|
|
|
vector<cell*> acells;
|
2019-11-14 15:51:50 +00:00
|
|
|
|
2020-01-06 21:18:10 +00:00
|
|
|
transmatrix adj(heptagon *h, int d) override { return tmatrices[h->fieldval][d]; }
|
2020-01-06 19:53:09 +00:00
|
|
|
|
|
|
|
heptagon *getOrigin() override { return allh[0]; }
|
|
|
|
|
|
|
|
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override;
|
2020-01-06 20:23:17 +00:00
|
|
|
|
|
|
|
void initialize(int cell_count);
|
|
|
|
vector<cell*>& allcells() override { return acells; }
|
2020-01-15 16:58:41 +00:00
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
vector<hyperpoint> get_vertices(cell* c) override { return cgi.vertices_only; }
|
2019-10-12 11:19:58 +00:00
|
|
|
};
|
2020-01-06 19:53:09 +00:00
|
|
|
#endif
|
|
|
|
|
2020-01-06 20:23:17 +00:00
|
|
|
void hrmap_quotient3::initialize(int cell_count) {
|
|
|
|
allh.resize(cell_count);
|
|
|
|
acells.clear();
|
|
|
|
tmatrices.resize(cell_count);
|
|
|
|
for(int a=0; a<cell_count; a++) {
|
2021-07-04 08:36:16 +00:00
|
|
|
allh[a] = init_heptagon(S7);
|
2020-01-06 20:23:17 +00:00
|
|
|
allh[a]->c7 = newCell(S7, allh[a]);
|
|
|
|
allh[a]->fieldval = a;
|
|
|
|
acells.push_back(allh[a]->c7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
transmatrix hrmap_quotient3::relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) {
|
|
|
|
if(h1 == h2) return Id;
|
|
|
|
int d = hr::celldistance(h2->c7, h1->c7);
|
2019-10-12 11:19:58 +00:00
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
for(int a=0; a<S7; a++) if(hr::celldistance(h1->move(a)->c7, h2->c7) < d)
|
|
|
|
return adj(h1, a) * relative_matrix(h2, h1->move(a), hint);
|
2020-01-16 15:50:07 +00:00
|
|
|
|
|
|
|
for(int a=0; a<S7; a++) println(hlog, "d=", d, " vs ", hr::celldistance(h1->move(a)->c7, h2->c7));
|
2020-01-06 19:53:09 +00:00
|
|
|
|
|
|
|
println(hlog, "error in hrmap_quotient3:::relative_matrix");
|
|
|
|
return Id;
|
|
|
|
}
|
|
|
|
|
2020-05-04 01:21:14 +00:00
|
|
|
#if CAP_CRYSTAL
|
2019-10-12 11:19:58 +00:00
|
|
|
int encode_coord(const crystal::coord& co) {
|
|
|
|
int c = 0;
|
|
|
|
for(int i=0; i<4; i++) c |= ((co[i]>>1) & 3) << (2*i);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
EX crystal::coord decode_coord(int a) {
|
|
|
|
crystal::coord co;
|
|
|
|
for(int i=0; i<4; i++) co[i] = (a & 3) * 2, a >>= 2;
|
|
|
|
return co;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hrmap_from_crystal : hrmap_quotient3 {
|
|
|
|
|
|
|
|
hrmap_from_crystal() {
|
2020-01-06 20:23:17 +00:00
|
|
|
initialize(256);
|
2019-10-12 11:19:58 +00:00
|
|
|
if(1) {
|
|
|
|
auto m = crystal::new_map();
|
|
|
|
dynamicval<hrmap*> cm(currentmap, m);
|
|
|
|
for(int a=0; a<256; a++) {
|
|
|
|
auto co = decode_coord(a);
|
|
|
|
heptagon *h1 = get_heptagon_at(co);
|
|
|
|
for(int d=0; d<8; d++) {
|
|
|
|
int b = encode_coord(crystal::get_coord(h1->cmove(d)));
|
|
|
|
allh[a]->c.connect(d, allh[b], h1->c.spin(d), false);
|
|
|
|
tmatrices[a].push_back(crystal::get_adj(h1, d));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-05-04 01:21:14 +00:00
|
|
|
#endif
|
2020-01-15 16:58:41 +00:00
|
|
|
|
|
|
|
struct hrmap_field3 : reg3::hrmap_quotient3 {
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2020-01-26 00:20:42 +00:00
|
|
|
fieldpattern::fpattern *f;
|
|
|
|
|
|
|
|
hrmap_field3(fieldpattern::fpattern *ptr) {
|
|
|
|
|
|
|
|
f = ptr;
|
2020-01-15 16:58:41 +00:00
|
|
|
|
2020-01-26 00:20:42 +00:00
|
|
|
auto lgr = f->local_group;
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2020-01-26 00:20:42 +00:00
|
|
|
int N = isize(f->matrices) / lgr;
|
2020-01-15 16:58:41 +00:00
|
|
|
initialize(N);
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2020-01-15 16:58:41 +00:00
|
|
|
vector<int> moveid(S7), movedir(lgr);
|
|
|
|
for(int s=0; s<lgr; s++)
|
2020-04-05 08:53:34 +00:00
|
|
|
for(int i=0; i<S7; i++) if(eqmatrix(f->fullv[s] * cgi.adjmoves[0], cgi.adjmoves[i]))
|
2020-01-15 16:58:41 +00:00
|
|
|
moveid[i] = s;
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2020-01-15 16:58:41 +00:00
|
|
|
for(int s=0; s<lgr; s++)
|
2020-04-05 08:53:34 +00:00
|
|
|
for(int i=0; i<S7; i++) if(hdist(tC0(inverse(f->fullv[s]) * cgi.adjmoves[0]), tC0(cgi.adjmoves[i])) < 1e-4)
|
2020-01-15 16:58:41 +00:00
|
|
|
movedir[s] = i;
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2020-01-15 16:58:41 +00:00
|
|
|
for(int a=0; a<N; a++) {
|
|
|
|
tmatrices[a].resize(S7);
|
|
|
|
for(int b=0; b<S7; b++) {
|
|
|
|
int k = lgr*a;
|
2021-05-20 20:59:24 +00:00
|
|
|
k = f->matcode[ f->mmul(f->mmul(f->matrices[k], f->matrices[moveid[b]]), f->P) ];
|
2020-01-26 00:20:42 +00:00
|
|
|
for(int l=0; l<lgr; l++) if(f->gmul(k, l) % lgr == 0) {
|
2020-04-05 08:53:34 +00:00
|
|
|
tmatrices[a][b] = cgi.adjmoves[b] * f->fullv[l];
|
2020-01-15 16:58:41 +00:00
|
|
|
allh[a]->c.connect(b, allh[k/lgr], movedir[l], false);
|
2019-03-15 12:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-15 16:58:41 +00:00
|
|
|
}
|
2019-03-15 15:42:14 +00:00
|
|
|
create_patterns();
|
|
|
|
}
|
|
|
|
|
|
|
|
set<cellwalker> plane;
|
|
|
|
|
|
|
|
void make_plane(cellwalker cw) {
|
|
|
|
if(plane.count(cw)) return;
|
|
|
|
plane.insert(cw);
|
|
|
|
for(int i=0; i<S7; i++)
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.dirs_adjacent[i][cw.spin])
|
2019-03-15 15:42:14 +00:00
|
|
|
make_plane(reg3::strafe(cw, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void create_patterns() {
|
2020-01-28 14:16:50 +00:00
|
|
|
DEBB(DF_GEOM, ("creating pattern = ", isize(allh)));
|
|
|
|
|
2019-03-15 15:42:14 +00:00
|
|
|
// also, strafe needs currentmap
|
|
|
|
dynamicval<hrmap*> c(currentmap, this);
|
|
|
|
|
|
|
|
if(S7 == 12) {
|
|
|
|
// Emerald in 534
|
|
|
|
cell *a = gamestart();
|
2019-04-04 12:36:58 +00:00
|
|
|
cell *b = a;
|
2019-03-15 15:42:14 +00:00
|
|
|
for(cell *c: allcells())
|
2020-01-28 14:16:50 +00:00
|
|
|
if(bounded_celldistance(a, c) == 5) {
|
2019-03-15 15:42:14 +00:00
|
|
|
b = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(cell *c: allcells())
|
2020-01-28 14:16:50 +00:00
|
|
|
if(bounded_celldistance(a, c) > bounded_celldistance(b, c))
|
2019-03-15 15:42:14 +00:00
|
|
|
c->master->zebraval |= 1;
|
|
|
|
|
|
|
|
// Vineyard in 534
|
|
|
|
b = (cellwalker(a, 0) + wstep + rev + wstep).at;
|
|
|
|
for(cell *c: allcells())
|
2020-01-28 14:16:50 +00:00
|
|
|
if(bounded_celldistance(a, c) == bounded_celldistance(b, c))
|
2019-03-15 15:42:14 +00:00
|
|
|
c->master->zebraval |= 2;
|
|
|
|
}
|
|
|
|
|
2020-01-26 00:21:07 +00:00
|
|
|
if(S7 == 6 && ginf[geometry].vertex == 5) {
|
2019-03-15 15:42:14 +00:00
|
|
|
// Emerald in 534
|
|
|
|
cell *a = gamestart();
|
|
|
|
for(cell *c: allcells())
|
2020-01-28 14:16:50 +00:00
|
|
|
if(bounded_celldistance(a, c) > 3)
|
2019-03-15 15:42:14 +00:00
|
|
|
c->master->zebraval |= 1;
|
|
|
|
|
|
|
|
// Vineyard in 435
|
|
|
|
make_plane(cellwalker(gamestart(), 0));
|
2020-01-28 09:35:54 +00:00
|
|
|
DEBB(DF_GEOM, ("plane size = ", isize(plane)));
|
2019-03-15 15:42:14 +00:00
|
|
|
|
|
|
|
set<int> plane_indices;
|
|
|
|
for(auto cw: plane) plane_indices.insert(cw.at->master->fieldval);
|
|
|
|
|
2020-03-25 12:47:06 +00:00
|
|
|
int fN = isize(f->matrices);
|
|
|
|
|
2019-03-15 15:42:14 +00:00
|
|
|
set<int> nwi;
|
2020-03-25 12:47:06 +00:00
|
|
|
for(int i=0; i<fN; i++) {
|
2019-03-15 15:42:14 +00:00
|
|
|
bool ok = true;
|
|
|
|
for(auto o: plane_indices) {
|
2020-01-28 18:47:27 +00:00
|
|
|
int j = f->gmul(i, o * f->local_group) / f->local_group;
|
2019-03-15 15:42:14 +00:00
|
|
|
if(plane_indices.count(j)) ok = false;
|
|
|
|
forCellEx(c1, allcells()[j]) if(plane_indices.count(c1->master->fieldval)) ok = false;
|
|
|
|
}
|
|
|
|
if(ok) nwi.insert(i);
|
|
|
|
}
|
|
|
|
|
2019-04-04 12:36:58 +00:00
|
|
|
int gpow = 0;
|
2019-03-15 15:42:14 +00:00
|
|
|
|
|
|
|
for(int i: nwi) {
|
|
|
|
int pw = 1;
|
|
|
|
int at = i;
|
|
|
|
while(true) {
|
2020-01-28 18:47:27 +00:00
|
|
|
at = f->gmul(at, i);
|
2019-03-15 15:42:14 +00:00
|
|
|
if(!nwi.count(at)) break;
|
|
|
|
pw++;
|
|
|
|
}
|
|
|
|
if(pw == 4) gpow = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int u = 0;
|
|
|
|
for(int a=0; a<5; a++) {
|
|
|
|
for(int o: plane_indices) {
|
2020-03-25 12:47:06 +00:00
|
|
|
int j = f->gmul(u, o * f->local_group) / f->local_group;
|
2019-03-15 15:42:14 +00:00
|
|
|
allcells()[j]->master->zebraval |= 2;
|
|
|
|
}
|
2020-01-28 18:47:27 +00:00
|
|
|
u = f->gmul(u, gpow);
|
2019-03-15 15:42:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-15 12:46:23 +00:00
|
|
|
}
|
2020-01-06 19:53:09 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief homology cover of the Seifert-Weber space */
|
2020-01-06 19:53:09 +00:00
|
|
|
namespace seifert_weber {
|
|
|
|
|
|
|
|
using crystal::coord;
|
|
|
|
|
|
|
|
vector<coord> periods;
|
|
|
|
|
|
|
|
int flip(int x) { return (x+6) % 12; }
|
|
|
|
|
|
|
|
void build_reps() {
|
|
|
|
// start_game();
|
|
|
|
for(int a=0; a<12; a++)
|
|
|
|
for(int b=0; b<12; b++)
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.dirs_adjacent[a][b])
|
2020-01-06 19:53:09 +00:00
|
|
|
for(int c=0; c<12; c++)
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.dirs_adjacent[a][c] && cgi.dirs_adjacent[b][c]) {
|
|
|
|
transmatrix t = build_matrix(tC0(cgi.adjmoves[a]), tC0(cgi.adjmoves[b]), tC0(cgi.adjmoves[c]), C0);
|
|
|
|
if(det(t) > 0) cgi.next_dir[a][b] = c;
|
2020-01-06 19:53:09 +00:00
|
|
|
}
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
set<coord> boundaries;
|
|
|
|
|
|
|
|
for(int a=0; a<12; a++)
|
2020-04-05 08:53:34 +00:00
|
|
|
for(int b=0; b<12; b++) if(cgi.dirs_adjacent[a][b]) {
|
2020-01-06 19:53:09 +00:00
|
|
|
coord res = crystal::c0;
|
|
|
|
int sa = a, sb = b;
|
|
|
|
do {
|
|
|
|
// printf("%d ", sa);
|
|
|
|
if(sa < 6) res[sa]++; else res[sa-6]--;
|
|
|
|
sa = flip(sa);
|
|
|
|
sb = flip(sb);
|
|
|
|
swap(sa, sb);
|
2020-04-05 08:53:34 +00:00
|
|
|
sb = cgi.next_dir[sa][sb];
|
2020-01-06 19:53:09 +00:00
|
|
|
// sb = next_dirsa][sb];
|
|
|
|
}
|
|
|
|
while(a != sa || b != sb);
|
|
|
|
// printf("\n");
|
|
|
|
if(res > crystal::c0)
|
|
|
|
boundaries.insert(res);
|
|
|
|
}
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
periods.clear();
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
for(int index = 5; index >= 0; index--) {
|
|
|
|
for(auto k: boundaries) println(hlog, k);
|
2020-01-28 09:35:54 +00:00
|
|
|
DEBB(DF_GEOM, ("simplifying..."));
|
2020-01-06 19:53:09 +00:00
|
|
|
|
|
|
|
for(auto by: boundaries) if(among(by[index], 1, -1)) {
|
2020-01-28 09:35:54 +00:00
|
|
|
DEBB(DF_GEOM, ("simplifying by ", by));
|
2020-01-06 19:53:09 +00:00
|
|
|
periods.push_back(by);
|
|
|
|
set<coord> nb;
|
|
|
|
|
|
|
|
for(auto v: boundaries)
|
|
|
|
if(v == by) ;
|
|
|
|
else if(v[index] % by[index] == 0)
|
|
|
|
nb.insert(v - by * (v[index] / by[index]));
|
|
|
|
else println(hlog, "error");
|
|
|
|
|
|
|
|
boundaries = move(nb);
|
|
|
|
break;
|
|
|
|
}
|
2019-03-15 12:46:23 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-14 15:51:50 +00:00
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
int get_rep(coord a) {
|
|
|
|
a = a - periods[0] * (a[5] / periods[0][5]);
|
|
|
|
a = a - periods[1] * (a[4] / periods[1][4]);
|
|
|
|
a = a - periods[2] * (a[3] / periods[2][3]);
|
|
|
|
for(int i=0; i<3; i++) a[i] = gmod(a[i], 5);
|
|
|
|
return a[2] * 25 + a[1] * 5 + a[0];
|
2019-03-15 12:46:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
coord decode(int id) {
|
|
|
|
coord res = crystal::c0;
|
|
|
|
for(int a=0; a<3; a++) res[a] = id % 5, id /= 5;
|
|
|
|
return res;
|
2019-04-08 14:16:16 +00:00
|
|
|
}
|
2020-01-06 19:53:09 +00:00
|
|
|
|
2020-01-06 20:24:21 +00:00
|
|
|
struct hrmap_singlecell : hrmap_quotient3 {
|
|
|
|
hrmap_singlecell(ld angle) {
|
|
|
|
initialize(1);
|
|
|
|
tmatrices[0].resize(S7);
|
|
|
|
for(int b=0; b<S7; b++) {
|
|
|
|
allh[0]->c.connect(b, allh[0], (b+S7/2) % S7, false);
|
2020-04-05 08:53:34 +00:00
|
|
|
transmatrix T = cgi.adjmoves[b];
|
2020-01-06 20:24:21 +00:00
|
|
|
hyperpoint p = tC0(T);
|
|
|
|
tmatrices[0][b] = rspintox(p) * xpush(hdist0(p)) * cspin(2, 1, angle) * spintox(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-01-06 19:53:09 +00:00
|
|
|
struct hrmap_seifert_cover : hrmap_quotient3 {
|
|
|
|
|
|
|
|
hrmap_seifert_cover() {
|
|
|
|
if(periods.empty()) build_reps();
|
2020-01-06 20:23:17 +00:00
|
|
|
initialize(125);
|
2020-01-06 19:53:09 +00:00
|
|
|
for(int a=0; a<125; a++) {
|
|
|
|
tmatrices[a].resize(12);
|
|
|
|
for(int b=0; b<12; b++) {
|
|
|
|
coord x = decode(a);
|
|
|
|
if(b < 6) x[b]++;
|
|
|
|
else x[b-6]--;
|
|
|
|
int a1 = get_rep(x);
|
|
|
|
allh[a]->c.connect(b, allh[a1], flip(b), false);
|
2020-04-05 08:53:34 +00:00
|
|
|
transmatrix T = cgi.adjmoves[b];
|
2020-01-06 19:53:09 +00:00
|
|
|
hyperpoint p = tC0(T);
|
|
|
|
tmatrices[a][b] = rspintox(p) * xpush(hdist0(p)) * cspin(2, 1, 108 * degree) * spintox(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2019-03-15 12:46:23 +00:00
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
struct hrmap_reg3 : hrmap {
|
|
|
|
|
|
|
|
heptagon *origin;
|
|
|
|
hrmap *binary_map;
|
2019-10-12 11:19:58 +00:00
|
|
|
hrmap_quotient3 *quotient_map;
|
2019-03-02 23:43:31 +00:00
|
|
|
|
Remove USE_UNORDERED_MAP because it has bit-rotted.
Trying to compile with `-DUSE_UNORDERED_MAP` produces lots of compiler errors
like these, because of missing `std::hash` specializations.
Also, `#define unordered_map map` is just evil!
```
./nonisotropic.cpp:875:36: note: in instantiation of template class 'std::__1::unordered_map<hr::nilv::mvec, hr::heptagon *,
std::__1::hash<hr::nilv::mvec>, std::__1::equal_to<hr::nilv::mvec>, std::__1::allocator<std::__1::pair<const hr::nilv::mvec, hr::heptagon
*> > >' requested here
unordered_map<mvec, heptagon*> at;
^
./nonisotropic.cpp:239:58: note: in instantiation of template class 'std::__1::unordered_map<std::__1::pair<hr::heptagon *, hr::heptagon *>,
hr::heptagon *, std::__1::hash<std::__1::pair<hr::heptagon *, hr::heptagon *> >, std::__1::equal_to<std::__1::pair<hr::heptagon *,
hr::heptagon *> >, std::__1::allocator<std::__1::pair<const std::__1::pair<hr::heptagon *, hr::heptagon *>, hr::heptagon *> > >'
requested here
unordered_map<pair<heptagon*, heptagon*>, heptagon*> at;
^
./nonisotropic.cpp:457:49: error: no matching member function for call to 'iadj'
while(h1->distance < h2->distance) back = iadj(h2, down) * back, h2 = h2->cmove(down);
^~~~
cell.cpp:42:15: note: candidate function not viable: no known conversion from 'hr::sn::hrmap_solnih' to 'hr::hrmap' for object argument
transmatrix iadj(heptagon *h, int d) {
^
cell.cpp:41:22: note: candidate function not viable: no known conversion from 'hr::sn::hrmap_solnih' to 'hr::hrmap' for object argument
struct transmatrix iadj(cell *c, int i) { cell *c1 = c->cmove(i); return adj(c1, c->c.spin(i)); }
^
```
2020-09-25 03:15:19 +00:00
|
|
|
map<heptagon*, pair<heptagon*, transmatrix>> reg_gmatrix;
|
|
|
|
map<heptagon*, vector<pair<heptagon*, transmatrix> > > altmap;
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2019-04-03 18:34:22 +00:00
|
|
|
vector<cell*> spherecells;
|
|
|
|
|
|
|
|
vector<cell*>& allcells() override {
|
|
|
|
if(sphere) return spherecells;
|
|
|
|
return hrmap::allcells();
|
|
|
|
}
|
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
hrmap_reg3() {
|
2021-07-04 08:36:16 +00:00
|
|
|
origin = init_heptagon(S7);
|
2019-03-02 23:43:31 +00:00
|
|
|
heptagon& h = *origin;
|
|
|
|
h.s = hsOrigin;
|
|
|
|
h.c7 = newCell(S7, origin);
|
2019-04-03 18:34:22 +00:00
|
|
|
if(sphere) spherecells.push_back(h.c7);
|
2019-03-03 00:11:37 +00:00
|
|
|
worst_error1 = 0, worst_error2 = 0;
|
2019-03-02 23:43:31 +00:00
|
|
|
|
|
|
|
dynamicval<hrmap*> cr(currentmap, this);
|
|
|
|
|
|
|
|
heptagon *alt = NULL;
|
|
|
|
transmatrix T = Id;
|
|
|
|
|
2019-10-10 11:15:08 +00:00
|
|
|
binary_map = nullptr;
|
|
|
|
quotient_map = nullptr;
|
|
|
|
|
|
|
|
#if CAP_FIELD
|
2020-10-15 14:33:52 +00:00
|
|
|
#if CAP_CRYSTAL
|
2019-10-12 11:19:58 +00:00
|
|
|
if(geometry == gSpace344) {
|
|
|
|
quotient_map = new hrmap_from_crystal;
|
|
|
|
}
|
2020-10-15 14:33:52 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if(geometry == gSpace535) {
|
2020-01-06 21:10:44 +00:00
|
|
|
quotient_map = new seifert_weber::hrmap_seifert_cover;
|
|
|
|
}
|
2020-01-15 16:58:41 +00:00
|
|
|
else if(hyperbolic) {
|
2020-01-26 00:20:42 +00:00
|
|
|
quotient_map = new hrmap_field3(&currfp);
|
2019-10-10 11:15:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-02-07 18:45:20 +00:00
|
|
|
h.zebraval = quotient_map ? quotient_map->allh[0]->zebraval : 0;
|
2019-10-10 11:15:08 +00:00
|
|
|
|
2020-10-15 14:33:52 +00:00
|
|
|
#if CAP_BT
|
2019-10-10 11:15:08 +00:00
|
|
|
if(hyperbolic) {
|
2019-03-02 23:43:31 +00:00
|
|
|
dynamicval<eGeometry> g(geometry, gBinary3);
|
2019-12-14 11:05:01 +00:00
|
|
|
bt::build_tmatrix();
|
2021-07-04 08:36:16 +00:00
|
|
|
alt = init_heptagon(S7);
|
2019-03-02 23:43:31 +00:00
|
|
|
alt->s = hsOrigin;
|
|
|
|
alt->alt = alt;
|
2019-12-14 11:05:01 +00:00
|
|
|
binary_map = bt::new_alt_map(alt);
|
2019-03-02 23:43:31 +00:00
|
|
|
T = xpush(.01241) * spin(1.4117) * xpush(0.1241) * cspin(0, 2, 1.1249) * xpush(0.07) * Id;
|
|
|
|
}
|
2020-10-15 14:33:52 +00:00
|
|
|
#endif
|
2019-03-02 23:43:31 +00:00
|
|
|
|
|
|
|
reg_gmatrix[origin] = make_pair(alt, T);
|
|
|
|
altmap[alt].emplace_back(origin, T);
|
2019-03-04 17:03:16 +00:00
|
|
|
|
|
|
|
celllister cl(origin->c7, 4, 100000, NULL);
|
|
|
|
for(cell *c: cl.lst) {
|
2019-11-26 23:39:41 +00:00
|
|
|
hyperpoint h = tC0(relative_matrix(c->master, origin, C0));
|
2020-04-05 08:53:34 +00:00
|
|
|
cgi.close_distances[bucketer(h)] = cl.getdist(c);
|
2019-03-04 17:03:16 +00:00
|
|
|
}
|
2019-03-02 23:43:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 00:11:37 +00:00
|
|
|
ld worst_error1, worst_error2;
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2019-05-13 15:17:05 +00:00
|
|
|
heptagon *getOrigin() override {
|
2019-03-02 23:43:31 +00:00
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
2019-03-09 00:00:46 +00:00
|
|
|
void fix_distances(heptagon *h, heptagon *h2) {
|
|
|
|
vector<heptagon*> to_fix;
|
|
|
|
|
|
|
|
auto fix_pair = [&] (heptagon *h, heptagon *h2) {
|
|
|
|
if(!h2) return;
|
|
|
|
if(h->distance > h2->distance+1) {
|
|
|
|
h->distance = h2->distance + 1;
|
|
|
|
to_fix.push_back(h);
|
|
|
|
}
|
|
|
|
else if(h2->distance > h->distance+1) {
|
|
|
|
h2->distance = h->distance + 1;
|
|
|
|
to_fix.push_back(h2);
|
|
|
|
}
|
|
|
|
if(h->alt && h->alt == h2->alt) {
|
|
|
|
if(altdist(h) > altdist(h2) + 1) {
|
|
|
|
altdist(h) = altdist(h2) + 1;
|
|
|
|
to_fix.push_back(h);
|
|
|
|
}
|
|
|
|
else if (altdist(h2) > altdist(h) + 1) {
|
|
|
|
altdist(h2) = altdist(h) + 1;
|
|
|
|
to_fix.push_back(h2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!h2) to_fix = {h};
|
|
|
|
else fix_pair(h, h2);
|
|
|
|
|
|
|
|
for(int i=0; i<isize(to_fix); i++) {
|
|
|
|
h = to_fix[i];
|
|
|
|
for(int j=0; j<S7; j++) fix_pair(h, h->move(j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
#define DEB 0
|
2019-03-15 13:26:24 +00:00
|
|
|
|
|
|
|
heptagon *counterpart(heptagon *h) {
|
|
|
|
return quotient_map->allh[h->fieldval];
|
|
|
|
}
|
2019-03-02 23:43:31 +00:00
|
|
|
|
2020-07-04 22:45:25 +00:00
|
|
|
void verify_neighbors(heptagon *alt, int steps, const hyperpoint& hT) {
|
|
|
|
ld err;
|
|
|
|
for(auto& p2: altmap[alt]) if((err = intval(tC0(p2.second), hT)) < 1e-3) {
|
|
|
|
println(hlog, "FAIL");
|
|
|
|
exit(3);
|
|
|
|
}
|
2020-10-15 14:33:52 +00:00
|
|
|
#if CAP_BT
|
2020-07-04 22:45:25 +00:00
|
|
|
if(steps) {
|
|
|
|
dynamicval<eGeometry> g(geometry, gBinary3);
|
|
|
|
dynamicval<hrmap*> cm(currentmap, binary_map);
|
|
|
|
for(int i=0; i<alt->type; i++)
|
|
|
|
verify_neighbors(alt->cmove(i), steps-1, currentmap->iadj(alt, i) * hT);
|
|
|
|
}
|
2020-10-15 14:33:52 +00:00
|
|
|
#endif
|
2020-07-04 22:45:25 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 15:17:05 +00:00
|
|
|
heptagon *create_step(heptagon *parent, int d) override {
|
2019-03-02 23:43:31 +00:00
|
|
|
auto& p1 = reg_gmatrix[parent];
|
|
|
|
if(DEB) println(hlog, "creating step ", parent, ":", d, ", at ", p1.first, tC0(p1.second));
|
|
|
|
heptagon *alt = p1.first;
|
2019-03-15 13:26:24 +00:00
|
|
|
#if CAP_FIELD
|
2020-04-05 08:53:34 +00:00
|
|
|
transmatrix T = p1.second * (quotient_map ? quotient_map->tmatrices[parent->fieldval][d] : cgi.adjmoves[d]);
|
2019-03-15 13:26:24 +00:00
|
|
|
#else
|
2020-04-05 08:53:34 +00:00
|
|
|
transmatrix T = p1.second * cgi.adjmoves[d];
|
2019-03-15 13:26:24 +00:00
|
|
|
#endif
|
2019-03-02 23:43:31 +00:00
|
|
|
transmatrix T1 = T;
|
2020-10-15 14:33:52 +00:00
|
|
|
#if CAP_BT
|
2019-03-02 23:43:31 +00:00
|
|
|
if(hyperbolic) {
|
|
|
|
dynamicval<eGeometry> g(geometry, gBinary3);
|
2019-03-08 21:38:44 +00:00
|
|
|
dynamicval<hrmap*> cm(currentmap, binary_map);
|
2019-11-14 15:51:50 +00:00
|
|
|
binary_map->virtualRebase(alt, T);
|
2019-03-02 23:43:31 +00:00
|
|
|
}
|
2020-10-15 14:33:52 +00:00
|
|
|
#endif
|
2020-05-09 08:41:15 +00:00
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
fixmatrix(T);
|
|
|
|
auto hT = tC0(T);
|
|
|
|
|
2020-05-09 08:41:15 +00:00
|
|
|
bool hopf = stretch::applicable();
|
2020-05-08 19:18:47 +00:00
|
|
|
|
|
|
|
if(hopf)
|
2020-05-09 08:41:15 +00:00
|
|
|
T = stretch::translate(hT);
|
2020-05-08 19:18:47 +00:00
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
if(DEB) println(hlog, "searching at ", alt, ":", hT);
|
|
|
|
|
|
|
|
if(DEB) for(auto& p2: altmap[alt]) println(hlog, "for ", tC0(p2.second), " intval is ", intval(tC0(p2.second), hT));
|
|
|
|
|
|
|
|
ld err;
|
|
|
|
|
|
|
|
for(auto& p2: altmap[alt]) if((err = intval(tC0(p2.second), hT)) < 1e-3) {
|
|
|
|
if(err > worst_error1) println(hlog, format("worst_error1 = %lg", double(worst_error1 = err)));
|
|
|
|
// println(hlog, "YES found in ", isize(altmap[alt]));
|
|
|
|
if(DEB) println(hlog, "-> found ", p2.first);
|
|
|
|
int fb = 0;
|
2020-05-08 19:18:47 +00:00
|
|
|
hyperpoint old = tC0(p1.second);;
|
|
|
|
if(!hopf) T * (inverse(T1) * old);
|
2019-03-15 13:26:24 +00:00
|
|
|
#if CAP_FIELD
|
2019-10-10 11:15:08 +00:00
|
|
|
if(quotient_map) {
|
2019-03-15 13:26:24 +00:00
|
|
|
p2.first->c.connect(counterpart(parent)->c.spin(d), parent, d, false);
|
2019-05-05 16:14:47 +00:00
|
|
|
fix_distances(p2.first, parent);
|
2019-03-15 13:26:24 +00:00
|
|
|
return p2.first;
|
|
|
|
}
|
|
|
|
#endif
|
2019-03-02 23:43:31 +00:00
|
|
|
for(int d2=0; d2<S7; d2++) {
|
2020-04-05 08:53:34 +00:00
|
|
|
hyperpoint back = p2.second * tC0(cgi.adjmoves[d2]);
|
2019-03-02 23:43:31 +00:00
|
|
|
if((err = intval(back, old)) < 1e-3) {
|
|
|
|
if(err > worst_error2) println(hlog, format("worst_error2 = %lg", double(worst_error2 = err)));
|
|
|
|
if(p2.first->move(d2)) println(hlog, "error: repeated edge");
|
|
|
|
p2.first->c.connect(d2, parent, d, false);
|
2019-03-09 00:00:46 +00:00
|
|
|
fix_distances(p2.first, parent);
|
2019-03-02 23:43:31 +00:00
|
|
|
fb++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(fb != 1) {
|
|
|
|
println(hlog, "found fb = ", fb);
|
|
|
|
println(hlog, old);
|
|
|
|
for(int d2=0; d2<S7; d2++) {
|
2020-04-05 08:53:34 +00:00
|
|
|
println(hlog, p2.second * tC0(cgi.adjmoves[d2]), " in distance ", intval(p2.second * tC0(cgi.adjmoves[d2]), old));
|
2019-03-02 23:43:31 +00:00
|
|
|
}
|
|
|
|
parent->c.connect(d, parent, d, false);
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
return p2.first;
|
|
|
|
}
|
|
|
|
|
2020-07-04 22:45:25 +00:00
|
|
|
if(extra_verification) verify_neighbors(alt, extra_verification, hT);
|
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
if(DEB) println(hlog, "-> not found");
|
2019-03-16 21:18:41 +00:00
|
|
|
int d2 = 0, fv = isize(reg_gmatrix);
|
2019-03-15 13:26:24 +00:00
|
|
|
#if CAP_FIELD
|
2019-10-10 11:15:08 +00:00
|
|
|
if(quotient_map) {
|
2019-03-15 13:26:24 +00:00
|
|
|
auto cp = counterpart(parent);
|
|
|
|
d2 = cp->c.spin(d);
|
|
|
|
fv = cp->c.move(d)->fieldval;
|
|
|
|
}
|
|
|
|
#endif
|
2020-05-08 19:18:47 +00:00
|
|
|
if(hopf) {
|
|
|
|
hyperpoint old = tC0(p1.second);
|
|
|
|
for(d2=0; d2<S7; d2++) {
|
|
|
|
hyperpoint back = T * tC0(cgi.adjmoves[d2]);
|
|
|
|
if((err = intval(back, old)) < 1e-3)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(d2 == S7) {
|
|
|
|
d2 = 0;
|
|
|
|
println(hlog, "Hopf connection failed");
|
|
|
|
}
|
|
|
|
println(hlog, "found d2 = ", d2);
|
|
|
|
}
|
2021-07-04 08:36:16 +00:00
|
|
|
heptagon *created = init_heptagon(S7);
|
2019-03-02 23:43:31 +00:00
|
|
|
created->c7 = newCell(S7, created);
|
2019-04-03 18:34:22 +00:00
|
|
|
if(sphere) spherecells.push_back(created->c7);
|
2019-03-15 15:42:14 +00:00
|
|
|
#if CAP_FIELD
|
2019-10-10 11:15:08 +00:00
|
|
|
if(quotient_map) {
|
2020-01-28 14:17:33 +00:00
|
|
|
created->emeraldval = fv;
|
2019-03-15 15:42:14 +00:00
|
|
|
created->zebraval = quotient_map->allh[fv]->zebraval;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2019-03-02 23:43:31 +00:00
|
|
|
created->zebraval = hrand(10);
|
2019-03-15 13:26:24 +00:00
|
|
|
created->fieldval = fv;
|
2019-03-09 00:00:46 +00:00
|
|
|
created->distance = parent->distance + 1;
|
2020-01-26 00:22:04 +00:00
|
|
|
created->fiftyval = 9999;
|
2019-03-02 23:43:31 +00:00
|
|
|
fixmatrix(T);
|
|
|
|
reg_gmatrix[created] = make_pair(alt, T);
|
|
|
|
altmap[alt].emplace_back(created, T);
|
2019-03-15 13:26:24 +00:00
|
|
|
created->c.connect(d2, parent, d, false);
|
2019-03-02 23:43:31 +00:00
|
|
|
return created;
|
|
|
|
}
|
|
|
|
|
2019-03-08 21:38:44 +00:00
|
|
|
~hrmap_reg3() {
|
2020-10-15 14:33:52 +00:00
|
|
|
#if CAP_BT
|
2019-03-09 00:00:46 +00:00
|
|
|
if(binary_map) {
|
|
|
|
dynamicval<eGeometry> g(geometry, gBinary3);
|
2019-03-09 00:18:47 +00:00
|
|
|
delete binary_map;
|
2019-03-09 00:00:46 +00:00
|
|
|
}
|
2020-10-15 14:33:52 +00:00
|
|
|
#endif
|
2019-03-15 13:26:24 +00:00
|
|
|
if(quotient_map) delete quotient_map;
|
2019-03-08 21:38:44 +00:00
|
|
|
clearfrom(origin);
|
|
|
|
}
|
|
|
|
|
2019-03-09 00:00:46 +00:00
|
|
|
map<heptagon*, int> reducers;
|
|
|
|
|
|
|
|
void link_alt(const cellwalker& hs) override {
|
|
|
|
auto h = hs.at->master;
|
|
|
|
altdist(h) = 0;
|
|
|
|
if(h->alt->s != hsOrigin) reducers[h] = hs.spin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void generateAlts(heptagon* h, int levs, bool link_cdata) override {
|
|
|
|
if(reducers.count(h)) {
|
|
|
|
heptspin hs(h, reducers[h]);
|
|
|
|
reducers.erase(h);
|
|
|
|
hs += wstep;
|
|
|
|
hs += rev;
|
|
|
|
altdist(hs.at) = altdist(h) - 1;
|
|
|
|
hs.at->alt = h->alt;
|
|
|
|
reducers[hs.at] = hs.spin;
|
2019-05-05 16:14:47 +00:00
|
|
|
fix_distances(hs.at, NULL);
|
2019-03-09 00:00:46 +00:00
|
|
|
}
|
|
|
|
for(int i=0; i<S7; i++) {
|
|
|
|
auto h2 = h->cmove(i);
|
|
|
|
if(h2->alt == NULL) {
|
|
|
|
h2->alt = h->alt;
|
|
|
|
altdist(h2) = altdist(h) + 1;
|
|
|
|
fix_distances(h2, NULL);
|
|
|
|
}
|
|
|
|
}
|
2019-03-08 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 17:47:04 +00:00
|
|
|
transmatrix adj(heptagon *h, int d) override {
|
2019-11-14 15:51:50 +00:00
|
|
|
#if CAP_FIELD
|
|
|
|
if(quotient_map) return quotient_map->adj(h, d);
|
|
|
|
else
|
|
|
|
#endif
|
2019-11-26 23:39:41 +00:00
|
|
|
return relative_matrix(h->cmove(d), h, C0);
|
2019-11-14 15:51:50 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 23:39:41 +00:00
|
|
|
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
2019-03-08 21:38:44 +00:00
|
|
|
auto p1 = reg_gmatrix[h1];
|
|
|
|
auto p2 = reg_gmatrix[h2];
|
|
|
|
transmatrix T = Id;
|
2020-10-15 14:33:52 +00:00
|
|
|
#if CAP_BT
|
2019-03-08 21:38:44 +00:00
|
|
|
if(hyperbolic) {
|
|
|
|
dynamicval<eGeometry> g(geometry, gBinary3);
|
|
|
|
dynamicval<hrmap*> cm(currentmap, binary_map);
|
2019-11-26 23:39:41 +00:00
|
|
|
T = binary_map->relative_matrix(p2.first, p1.first, hint);
|
2019-03-08 21:38:44 +00:00
|
|
|
}
|
2020-10-15 14:33:52 +00:00
|
|
|
#endif
|
|
|
|
T = inverse(p1.second) * T * p2.second;
|
2019-10-26 22:45:34 +00:00
|
|
|
if(elliptic && T[LDIM][LDIM] < 0) T = centralsym * T;
|
|
|
|
return T;
|
2019-03-08 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 14:16:16 +00:00
|
|
|
vector<hyperpoint> get_vertices(cell* c) override {
|
2020-04-05 08:53:34 +00:00
|
|
|
return cgi.vertices_only;
|
2019-04-08 14:16:16 +00:00
|
|
|
}
|
2019-03-02 23:43:31 +00:00
|
|
|
};
|
2020-01-26 00:23:10 +00:00
|
|
|
|
|
|
|
struct hrmap_reg3_rule : hrmap {
|
|
|
|
|
|
|
|
heptagon *origin;
|
|
|
|
reg3::hrmap_quotient3 *quotient_map;
|
2020-01-28 14:17:33 +00:00
|
|
|
reg3::hrmap_quotient3 *emerald_map;
|
2020-01-26 00:23:10 +00:00
|
|
|
|
|
|
|
fieldpattern::fpattern fp;
|
|
|
|
|
2020-01-28 10:58:34 +00:00
|
|
|
vector<int> root;
|
2020-01-26 00:23:10 +00:00
|
|
|
string other;
|
|
|
|
vector<short> children;
|
|
|
|
|
|
|
|
vector<int> otherpos;
|
|
|
|
|
|
|
|
void load_ruleset(string fname) {
|
2021-06-01 12:24:22 +00:00
|
|
|
string buf;
|
2021-06-03 10:26:36 +00:00
|
|
|
#if ISANDROID || ISIOS
|
2021-06-01 12:24:22 +00:00
|
|
|
buf = get_asset(fname);
|
|
|
|
#else
|
2020-01-26 00:23:10 +00:00
|
|
|
FILE *f = fopen(fname.c_str(), "rb");
|
2020-05-15 23:30:33 +00:00
|
|
|
if(!f) f = fopen((rsrcdir + fname).c_str(), "rb");
|
2020-01-26 00:23:10 +00:00
|
|
|
buf.resize(1000000);
|
|
|
|
int qty = fread(&buf[0], 1, 1000000, f);
|
|
|
|
buf.resize(qty);
|
2021-06-01 12:24:22 +00:00
|
|
|
fclose(f);
|
|
|
|
#endif
|
2020-01-26 00:23:10 +00:00
|
|
|
|
|
|
|
shstream ins(decompress_string(buf));
|
2021-05-20 21:06:02 +00:00
|
|
|
dynamicval<bool> q(fieldpattern::use_quotient_fp, true);
|
2020-01-26 00:23:10 +00:00
|
|
|
hread_fpattern(ins, fp);
|
|
|
|
|
|
|
|
hread(ins, root);
|
|
|
|
hread(ins, children);
|
|
|
|
hread(ins, other);
|
|
|
|
}
|
|
|
|
|
2020-03-27 20:47:09 +00:00
|
|
|
/** \brief address = (fieldvalue, state) */
|
2020-01-28 09:35:41 +00:00
|
|
|
typedef pair<int, int> address;
|
|
|
|
|
|
|
|
/** nles[x] lists the addresses from which we can reach address x
|
|
|
|
* without ever ending in the starting point */
|
|
|
|
|
|
|
|
map<address, set<address>> nonlooping_earlier_states;
|
|
|
|
|
2020-01-29 18:23:31 +00:00
|
|
|
vector<vector<int>> possible_states;
|
|
|
|
|
2020-01-28 09:35:41 +00:00
|
|
|
void find_mappings() {
|
|
|
|
auto &nles = nonlooping_earlier_states;
|
|
|
|
nles.clear();
|
2020-01-28 10:58:34 +00:00
|
|
|
vector<address> bfs;
|
2020-01-29 17:20:14 +00:00
|
|
|
int qty = isize(quotient_map->allh);
|
|
|
|
if(geometry == gSpace535) qty = 1;
|
|
|
|
for(int i=0; i<qty; i++)
|
2020-01-28 10:58:34 +00:00
|
|
|
bfs.emplace_back(i, root[i]);
|
2020-01-28 09:35:41 +00:00
|
|
|
auto mov = [&] (int fv, int d) {
|
2020-01-29 17:20:14 +00:00
|
|
|
if(geometry == gSpace535) return 0;
|
2020-01-28 09:35:41 +00:00
|
|
|
return quotient_map->allh[fv]->move(d)->fieldval;
|
|
|
|
};
|
|
|
|
int qstate = isize(children) / S7;
|
|
|
|
DEBB(DF_GEOM, ("qstate = ", qstate));
|
|
|
|
for(int i=0; i<isize(bfs); i++) {
|
|
|
|
address last = bfs[i];
|
|
|
|
int state = last.second;
|
|
|
|
int fv = last.first;
|
|
|
|
for(int d=0; d<S7; d++) {
|
|
|
|
int nstate = children[state*S7+d];
|
2021-05-21 23:25:41 +00:00
|
|
|
if(nstate < -1) nstate += (1<<16);
|
2020-01-28 09:35:41 +00:00
|
|
|
if(nstate >= 0) {
|
|
|
|
address next = {mov(fv, d), nstate};
|
|
|
|
if(!nles.count(next)) bfs.push_back(next);
|
|
|
|
nles[next].insert(last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<int> q(qstate, 0);
|
|
|
|
for(auto p: bfs) q[p.second]++;
|
|
|
|
vector<int> q2(isize(quotient_map->allh)+1, 0);
|
|
|
|
for(auto p: q) q2[p]++;
|
|
|
|
DEBB(DF_GEOM, ("q2 = ", q2));
|
|
|
|
|
2020-01-28 10:58:34 +00:00
|
|
|
bfs = {};
|
2020-01-29 17:20:14 +00:00
|
|
|
for(int i=0; i<qty; i++)
|
2020-01-28 10:58:34 +00:00
|
|
|
bfs.emplace_back(i, root[i]);
|
2020-01-28 09:35:41 +00:00
|
|
|
for(int i=0; i<isize(bfs); i++) {
|
|
|
|
address last = bfs[i];
|
|
|
|
int state = last.second;
|
|
|
|
int fv = last.first;
|
|
|
|
for(int d=0; d<S7; d++) {
|
|
|
|
int nstate = children[state*S7+d];
|
2021-05-21 23:25:41 +00:00
|
|
|
if(nstate < -1) nstate += (1<<16);
|
2020-01-28 09:35:41 +00:00
|
|
|
if(nstate >= 0) {
|
|
|
|
address next = {mov(fv, d), nstate};
|
|
|
|
if(!nles.count(next)) continue;
|
|
|
|
int c = isize(nles[next]);
|
|
|
|
nles[next].erase(last);
|
|
|
|
if(nles[next].empty() && c) {
|
|
|
|
nles.erase(next);
|
|
|
|
bfs.push_back(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBB(DF_GEOM, ("removed cases = ", isize(bfs)));
|
2020-01-29 18:23:31 +00:00
|
|
|
|
2021-05-21 23:26:31 +00:00
|
|
|
// just the number of FV's
|
|
|
|
int pstable = 0;
|
|
|
|
for(auto& p: nonlooping_earlier_states)
|
|
|
|
pstable = max(pstable, p.first.first+1);
|
|
|
|
|
|
|
|
println(hlog, "pstable size = ", pstable, " (states: ", qstate, ")");
|
|
|
|
|
|
|
|
possible_states.resize(pstable);
|
2020-01-29 18:23:31 +00:00
|
|
|
for(auto& p: nonlooping_earlier_states)
|
|
|
|
possible_states[p.first.first].push_back(p.first.second);
|
2020-01-28 09:35:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 00:23:10 +00:00
|
|
|
hrmap_reg3_rule() : fp(0) {
|
2021-05-20 21:14:00 +00:00
|
|
|
|
|
|
|
load_ruleset(get_rule_filename());
|
2020-01-26 00:23:10 +00:00
|
|
|
|
2021-07-04 08:36:16 +00:00
|
|
|
origin = init_heptagon(S7);
|
2020-01-26 00:23:10 +00:00
|
|
|
heptagon& h = *origin;
|
|
|
|
h.s = hsOrigin;
|
2020-01-28 10:58:34 +00:00
|
|
|
h.fiftyval = root[0];
|
2020-01-26 00:23:10 +00:00
|
|
|
h.c7 = newCell(S7, origin);
|
|
|
|
|
|
|
|
int opos = 0;
|
|
|
|
for(int c: children) {
|
2021-05-21 23:25:41 +00:00
|
|
|
if(c < -1) c += (1<<16);
|
2020-01-26 00:23:10 +00:00
|
|
|
if(c >= 0)
|
|
|
|
otherpos.push_back(-1);
|
|
|
|
else {
|
|
|
|
otherpos.push_back(opos);
|
|
|
|
while(other[opos] != ',') opos++;
|
|
|
|
opos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
quotient_map = nullptr;
|
|
|
|
|
|
|
|
if(geometry == gSpace535)
|
|
|
|
quotient_map = new seifert_weber::hrmap_seifert_cover();
|
2021-06-09 02:33:55 +00:00
|
|
|
#if CAP_CRYSTAL
|
2021-05-20 21:14:00 +00:00
|
|
|
else if(geometry == gSpace344)
|
|
|
|
quotient_map = new hrmap_from_crystal;
|
2021-06-09 02:33:55 +00:00
|
|
|
#endif
|
2020-01-26 00:23:10 +00:00
|
|
|
else
|
2021-05-20 21:14:00 +00:00
|
|
|
quotient_map = new hrmap_field3(&fp);
|
2020-01-28 14:17:33 +00:00
|
|
|
|
|
|
|
if(geometry == gSpace535)
|
|
|
|
emerald_map = new seifert_weber::hrmap_seifert_cover();
|
2021-06-09 02:33:55 +00:00
|
|
|
#if CAP_CRYSTAL
|
2021-05-20 21:14:00 +00:00
|
|
|
else if(geometry == gSpace344)
|
|
|
|
emerald_map = new hrmap_from_crystal;
|
2021-06-09 02:33:55 +00:00
|
|
|
#endif
|
2020-01-28 14:17:33 +00:00
|
|
|
else
|
|
|
|
emerald_map = new hrmap_field3(&currfp);
|
|
|
|
h.emeraldval = 0;
|
2020-01-28 09:35:41 +00:00
|
|
|
|
|
|
|
find_mappings();
|
2020-01-26 00:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
heptagon *getOrigin() override {
|
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEB 0
|
|
|
|
|
|
|
|
heptagon *counterpart(heptagon *h) {
|
|
|
|
return quotient_map->allh[h->fieldval];
|
|
|
|
}
|
2020-01-28 14:17:33 +00:00
|
|
|
|
2020-01-28 18:47:41 +00:00
|
|
|
vector<short> evmemo;
|
2020-01-28 14:17:33 +00:00
|
|
|
|
|
|
|
void find_emeraldval(heptagon *target, heptagon *parent, int d) {
|
2020-01-29 17:20:14 +00:00
|
|
|
if(geometry == gSpace535) {
|
|
|
|
target->emeraldval = target->fieldval;
|
|
|
|
target->zebraval = 0;
|
|
|
|
return;
|
|
|
|
}
|
2020-05-31 15:12:45 +00:00
|
|
|
generate_cellrotations();
|
2020-01-28 14:17:33 +00:00
|
|
|
auto& cr = cgi.cellrotations;
|
2020-01-28 18:47:41 +00:00
|
|
|
if(evmemo.empty()) {
|
|
|
|
println(hlog, "starting");
|
|
|
|
map<int, int> matrix_hashtable;
|
|
|
|
auto matrix_hash = [] (const transmatrix& M) {
|
|
|
|
return bucketer(M[0][0])
|
|
|
|
+ bucketer(M[0][1]) * 71
|
|
|
|
+ bucketer(M[0][2]) * 113
|
|
|
|
+ bucketer(M[1][0]) * 1301
|
|
|
|
+ bucketer(M[1][1]) * 1703
|
|
|
|
+ bucketer(M[1][2]) * 17031
|
|
|
|
+ bucketer(M[2][2]) * 2307
|
|
|
|
+ bucketer(M[2][0]) * 2311
|
|
|
|
+ bucketer(M[2][1]) * 10311;
|
|
|
|
};
|
|
|
|
for(int i=0; i<isize(cr); i++) matrix_hashtable[matrix_hash(cr[i].M)] = cr[i].inverse_id;
|
|
|
|
println(hlog, "ids size = ", isize(matrix_hashtable));
|
2020-01-28 14:17:33 +00:00
|
|
|
|
2020-01-28 18:47:41 +00:00
|
|
|
for(int eid=0; eid<isize(emerald_map->allh); eid++)
|
|
|
|
for(int k0=0; k0<isize(cr); k0++)
|
|
|
|
for(int fv=0; fv<isize(quotient_map->allh); fv++) {
|
|
|
|
for(int d=0; d<S7; d++) {
|
|
|
|
int ed = cr[k0].mapping[d];
|
|
|
|
auto cpart = emerald_map->allh[eid];
|
|
|
|
int eid1 = emerald_map->allh[eid]->move(ed)->fieldval;
|
|
|
|
const transmatrix& X = cr[cr[k0].inverse_id].M;
|
|
|
|
transmatrix U = quotient_map->iadj(quotient_map->allh[fv], d) * X * emerald_map->adj(cpart, ed);
|
|
|
|
int k1 = matrix_hashtable[matrix_hash(U)];
|
|
|
|
/* for(int ik1=0; ik1<isize(cr); ik1++) {
|
|
|
|
auto& mX1 = cr[ik1].M;
|
|
|
|
if(eqmatrix(mX1, U)) k1 = cr[ik1].inverse_id;
|
|
|
|
} */
|
|
|
|
evmemo.push_back(eid1 * isize(cr) + k1);
|
|
|
|
}
|
2020-01-28 14:17:33 +00:00
|
|
|
}
|
2020-01-28 18:47:41 +00:00
|
|
|
println(hlog, "generated ", isize(evmemo));
|
2020-01-28 14:17:33 +00:00
|
|
|
}
|
2020-01-28 18:47:41 +00:00
|
|
|
int memo_id = parent->emeraldval;
|
|
|
|
memo_id = memo_id * isize(quotient_map->allh) + parent->fieldval;
|
|
|
|
memo_id = memo_id * S7 + d;
|
|
|
|
target->emeraldval = evmemo[memo_id];
|
|
|
|
target->zebraval = emerald_map->allh[target->emeraldval / isize(cr)]->zebraval;
|
2020-01-28 14:17:33 +00:00
|
|
|
}
|
2020-01-26 00:23:10 +00:00
|
|
|
|
|
|
|
heptagon *create_step(heptagon *parent, int d) override {
|
|
|
|
int id = parent->fiftyval;
|
2021-05-21 23:25:41 +00:00
|
|
|
if(id < 0) id += (1<<16);
|
2020-01-26 00:23:10 +00:00
|
|
|
|
|
|
|
auto cp = counterpart(parent);
|
|
|
|
int d2 = cp->c.spin(d);
|
|
|
|
int fv = cp->c.move(d)->fieldval;
|
|
|
|
|
|
|
|
// indenter ind(2);
|
|
|
|
|
|
|
|
heptagon *res = nullptr;
|
|
|
|
|
|
|
|
int id1 = children[S7*id+d];
|
|
|
|
int pos = otherpos[S7*id+d];
|
2021-05-21 23:25:41 +00:00
|
|
|
if(id1 < -1) id1 += (1<<16);
|
2020-07-04 11:13:37 +00:00
|
|
|
|
|
|
|
if(id1 == -1 && false) {
|
|
|
|
int kk = pos;
|
|
|
|
string s;
|
|
|
|
while(other[kk] != ',') s += other[kk++];
|
|
|
|
println(hlog, "id=", id, " d=", d, " d2=", d2, " id1=", id1, " pos=", pos, " s = ", s);
|
|
|
|
}
|
|
|
|
|
2020-01-26 00:23:10 +00:00
|
|
|
if(id1 != -1) {
|
2021-07-04 08:36:16 +00:00
|
|
|
res = init_heptagon(S7);
|
2020-01-26 00:23:10 +00:00
|
|
|
if(parent->c7)
|
|
|
|
res->c7 = newCell(S7, res);
|
|
|
|
res->fieldval = fv;
|
|
|
|
res->distance = parent->distance + 1;
|
2020-01-28 14:17:33 +00:00
|
|
|
res->fiftyval = id1;
|
|
|
|
find_emeraldval(res, parent, d);
|
2020-01-26 00:23:10 +00:00
|
|
|
// res->c.connect(d2, parent, d, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(other[pos] == ('A' + d) && other[pos+1] == ',') {
|
2021-07-04 08:36:16 +00:00
|
|
|
res = init_heptagon(S7);
|
2020-01-26 00:23:10 +00:00
|
|
|
res->alt = parent->alt;
|
|
|
|
res->fieldval = fv;
|
|
|
|
res->distance = parent->distance - 1;
|
|
|
|
vector<int> possible;
|
2020-01-29 17:20:14 +00:00
|
|
|
int pfv = parent->fieldval;
|
|
|
|
if(geometry == gSpace535) pfv = 0;
|
2020-02-14 18:12:04 +00:00
|
|
|
for(auto s: nonlooping_earlier_states[address{pfv, id}]) possible.push_back(s.second);
|
2020-01-26 00:23:10 +00:00
|
|
|
id1 = hrand_elt(possible, 0);
|
|
|
|
res->fiftyval = id1;
|
2020-01-28 14:17:33 +00:00
|
|
|
find_emeraldval(res, parent, d);
|
2020-01-26 00:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
heptagon *at = parent;
|
|
|
|
while(other[pos] != ',') {
|
|
|
|
int dir = (other[pos++] & 31) - 1;
|
|
|
|
// println(hlog, "from ", at, " go dir ", dir);
|
|
|
|
at = at->cmove(dir);
|
|
|
|
}
|
|
|
|
res = at;
|
|
|
|
}
|
|
|
|
|
2021-03-24 19:25:44 +00:00
|
|
|
if(!res) throw hr_exception("res missing");
|
2020-01-26 00:23:10 +00:00
|
|
|
|
|
|
|
if(res->move(d2)) println(hlog, "res conflict");
|
|
|
|
|
|
|
|
res->c.connect(d2, parent, d, false);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
~hrmap_reg3_rule() {
|
|
|
|
if(quotient_map) delete quotient_map;
|
|
|
|
clearfrom(origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
transmatrix adj(heptagon *h, int d) override {
|
|
|
|
return quotient_map->adj(h, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
2020-01-28 10:22:49 +00:00
|
|
|
return relative_matrix_recursive(h2, h1);
|
2020-01-26 00:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vector<hyperpoint> get_vertices(cell* c) override {
|
2020-04-05 08:53:34 +00:00
|
|
|
return cgi.vertices_only;
|
2020-01-26 00:23:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hrmap_reg3_rule_alt : hrmap {
|
|
|
|
|
|
|
|
heptagon *origin;
|
|
|
|
|
|
|
|
hrmap_reg3_rule_alt(heptagon *o) {
|
|
|
|
origin = o;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
EX hrmap *new_alt_map(heptagon *o) {
|
|
|
|
return new hrmap_reg3_rule_alt(o);
|
|
|
|
}
|
|
|
|
|
2020-01-28 11:43:53 +00:00
|
|
|
EX void link_structures(heptagon *h, heptagon *alt, hstate firststate) {
|
|
|
|
auto cm = (hrmap_reg3_rule*) currentmap;
|
2020-01-26 00:23:10 +00:00
|
|
|
alt->fieldval = h->fieldval;
|
2020-01-29 17:20:14 +00:00
|
|
|
if(geometry == gSpace535) alt->fieldval = 0;
|
2020-01-28 11:43:53 +00:00
|
|
|
if(firststate == hsOrigin) {
|
|
|
|
alt->fiftyval = cm->root[alt->fieldval];
|
|
|
|
return;
|
|
|
|
}
|
2020-01-29 18:23:31 +00:00
|
|
|
vector<int>& choices = cm->possible_states[alt->fieldval];
|
2020-01-28 09:35:41 +00:00
|
|
|
vector<int> choices2;
|
|
|
|
for(auto c: choices) {
|
|
|
|
bool ok = true;
|
|
|
|
for(int d=0; d<12; d++)
|
|
|
|
if(h->cmove(d)->distance < h->distance)
|
|
|
|
if(cm->children[S7*c+d] == -1)
|
|
|
|
ok = false;
|
|
|
|
if(ok) choices2.push_back(c);
|
|
|
|
}
|
2020-01-29 17:20:14 +00:00
|
|
|
alt->fiftyval = hrand_elt(choices2, -1);
|
2020-01-26 00:23:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 09:35:41 +00:00
|
|
|
EX bool reg3_rule_available = true;
|
2021-05-20 21:14:00 +00:00
|
|
|
EX string other_rule = "";
|
|
|
|
|
|
|
|
EX string get_rule_filename() {
|
|
|
|
if(other_rule != "") return other_rule;
|
|
|
|
switch(geometry) {
|
|
|
|
case gSpace336: return "honeycomb-rules-336.dat";
|
|
|
|
case gSpace344: return "honeycomb-rules-344.dat";
|
|
|
|
// case gSpace345: return "honeycomb-rules-345.dat";
|
|
|
|
case gSpace353: return "honeycomb-rules-353.dat";
|
|
|
|
case gSpace354: return "honeycomb-rules-354.dat";
|
|
|
|
// case gSpace355: return "honeycomb-rules-355.dat";
|
|
|
|
case gSpace435: return "honeycomb-rules-435.dat";
|
|
|
|
case gSpace436: return "honeycomb-rules-436.dat";
|
|
|
|
case gSpace534: return "honeycomb-rules-534.dat";
|
|
|
|
case gSpace535: return "honeycomb-rules-535.dat";
|
|
|
|
case gSpace536: return "honeycomb-rules-536.dat";
|
|
|
|
|
|
|
|
default: return "";
|
|
|
|
}
|
|
|
|
}
|
2020-01-28 09:35:41 +00:00
|
|
|
|
|
|
|
EX bool in_rule() {
|
2021-05-20 21:14:00 +00:00
|
|
|
return reg3_rule_available && get_rule_filename() != "";
|
2020-01-26 00:23:10 +00:00
|
|
|
}
|
2020-07-04 23:02:15 +00:00
|
|
|
|
|
|
|
EX int rule_get_root(int i) {
|
|
|
|
return ((hrmap_reg3_rule*)currentmap)->root[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
EX const vector<short>& rule_get_children() {
|
|
|
|
return ((hrmap_reg3_rule*)currentmap)->children;
|
|
|
|
}
|
|
|
|
|
2019-08-09 20:37:11 +00:00
|
|
|
EX hrmap* new_map() {
|
2020-01-06 19:53:09 +00:00
|
|
|
if(geometry == gSeifertCover) return new seifert_weber::hrmap_seifert_cover;
|
2020-01-06 20:24:21 +00:00
|
|
|
if(geometry == gSeifertWeber) return new seifert_weber::hrmap_singlecell(108*degree);
|
|
|
|
if(geometry == gHomologySphere) return new seifert_weber::hrmap_singlecell(36*degree);
|
2020-01-26 00:20:42 +00:00
|
|
|
if(quotient && !sphere) return new hrmap_field3(&currfp);
|
2020-01-28 10:58:34 +00:00
|
|
|
if(in_rule()) return new hrmap_reg3_rule;
|
2019-03-02 23:43:31 +00:00
|
|
|
return new hrmap_reg3;
|
|
|
|
}
|
|
|
|
|
|
|
|
hrmap_reg3* regmap() {
|
|
|
|
return ((hrmap_reg3*) currentmap);
|
|
|
|
}
|
|
|
|
|
2020-01-28 10:58:34 +00:00
|
|
|
EX int quotient_count() {
|
|
|
|
return isize(regmap()->quotient_map->allh);
|
|
|
|
}
|
|
|
|
|
2020-03-06 01:36:11 +00:00
|
|
|
/** This is a generalization of hyperbolic_celldistance in expansion.cpp to three dimensions.
|
|
|
|
It still assumes that there are at most 4 cells around every edge, and that distances from
|
|
|
|
the origin are known, so it works only in {5,3,4}.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int celldistance_534(cell *c1, cell *c2) {
|
|
|
|
int d1 = celldist(c1);
|
|
|
|
int d2 = celldist(c2);
|
|
|
|
|
|
|
|
vector<cell*> s1 = {c1};
|
|
|
|
vector<cell*> s2 = {c2};
|
|
|
|
int best = 99999999;
|
|
|
|
int d0 = 0;
|
|
|
|
|
|
|
|
auto go_nearer = [&] (vector<cell*>& v, int& d) {
|
|
|
|
vector<cell*> w;
|
|
|
|
for(cell *c: v)
|
|
|
|
forCellEx(c1, c)
|
|
|
|
if(celldist(c1) < d)
|
|
|
|
w.push_back(c1);
|
|
|
|
sort(w.begin(), w.end());
|
|
|
|
d--; d0++;
|
|
|
|
auto last = std::unique(w.begin(), w.end());
|
|
|
|
w.erase(last, w.end());
|
|
|
|
v = w;
|
|
|
|
};
|
|
|
|
|
|
|
|
while(d0 < best) {
|
|
|
|
for(cell *a1: s1) for(cell *a2: s2) {
|
|
|
|
if(a1 == a2) best = min(best, d0);
|
|
|
|
else if(isNeighbor(a1, a2)) best = min(best, d0+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d1 == 0 && d2 == 0) break;
|
|
|
|
|
|
|
|
if(d1 >= d2) go_nearer(s1, d1);
|
|
|
|
if(d1 < d2) go_nearer(s2, d2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-09 20:37:11 +00:00
|
|
|
EX int celldistance(cell *c1, cell *c2) {
|
2019-03-02 23:43:31 +00:00
|
|
|
if(c1 == c2) return 0;
|
2019-03-09 00:00:46 +00:00
|
|
|
if(c1 == currentmap->gamestart()) return c2->master->distance;
|
|
|
|
if(c2 == currentmap->gamestart()) return c1->master->distance;
|
2020-03-06 01:36:11 +00:00
|
|
|
|
|
|
|
if(geometry == gSpace534) return celldistance_534(c1, c2);
|
2019-03-04 17:03:16 +00:00
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
auto r = regmap();
|
2019-03-04 17:03:16 +00:00
|
|
|
|
2019-11-26 23:39:41 +00:00
|
|
|
hyperpoint h = tC0(r->relative_matrix(c1->master, c2->master, C0));
|
2019-03-04 17:03:16 +00:00
|
|
|
int b = bucketer(h);
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.close_distances.count(b)) return cgi.close_distances[b];
|
2020-01-28 09:35:41 +00:00
|
|
|
|
|
|
|
if(in_rule())
|
|
|
|
return clueless_celldistance(c1, c2);
|
2019-03-04 17:03:16 +00:00
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
dynamicval<eGeometry> g(geometry, gBinary3);
|
2020-10-15 14:33:52 +00:00
|
|
|
#if CAP_BT
|
2019-12-14 11:05:01 +00:00
|
|
|
return 20 + bt::celldistance3(r->reg_gmatrix[c1->master].first, r->reg_gmatrix[c2->master].first);
|
2020-10-15 14:33:52 +00:00
|
|
|
#else
|
|
|
|
return 20;
|
|
|
|
#endif
|
2019-03-02 23:43:31 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 20:37:11 +00:00
|
|
|
EX bool pseudohept(cell *c) {
|
2019-03-08 21:38:44 +00:00
|
|
|
auto m = regmap();
|
2020-01-06 20:24:21 +00:00
|
|
|
if(cgflags & qSINGLE) return true;
|
2020-05-15 09:46:26 +00:00
|
|
|
if(fake::in()) return FPIU(reg3::pseudohept(c));
|
2019-03-02 23:43:31 +00:00
|
|
|
if(sphere) {
|
2019-11-26 23:39:41 +00:00
|
|
|
hyperpoint h = tC0(m->relative_matrix(c->master, regmap()->origin, C0));
|
2019-03-02 23:43:31 +00:00
|
|
|
if(S7 == 12) {
|
|
|
|
hyperpoint h1 = cspin(0, 1, atan2(16, 69) + M_PI/4) * h;
|
|
|
|
for(int i=0; i<4; i++) if(abs(abs(h1[i]) - .5) > .01) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(S7 == 8)
|
|
|
|
return h[3] >= .99 || h[3] <= -.99 || abs(h[3]) < .01;
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.loop == 3 && cgi.face == 3 && S7 == 4)
|
2019-03-08 21:38:44 +00:00
|
|
|
return c == m->gamestart();
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.loop == 4 && cgi.face == 3)
|
2019-03-02 23:43:31 +00:00
|
|
|
return abs(h[3]) > .9;
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.loop == 3 && cgi.face == 4)
|
2019-03-02 23:43:31 +00:00
|
|
|
return abs(h[3]) > .9;
|
2020-04-05 08:53:34 +00:00
|
|
|
if(cgi.loop == 5 && cgi.face == 3)
|
2019-03-02 23:43:31 +00:00
|
|
|
return abs(h[3]) > .99 || abs(h[0]) > .99 || abs(h[1]) > .99 || abs(h[2]) > .99;
|
|
|
|
}
|
2019-03-15 11:47:37 +00:00
|
|
|
// chessboard pattern in 534
|
2019-03-21 18:23:27 +00:00
|
|
|
if(geometry == gField534)
|
|
|
|
return hr::celldistance(c, currentmap->gamestart()) & 1;
|
2020-01-06 19:53:09 +00:00
|
|
|
if(geometry == gCrystal344 || geometry == gCrystal534 || geometry == gSeifertCover)
|
2019-10-12 09:24:29 +00:00
|
|
|
return false;
|
2020-01-15 16:58:41 +00:00
|
|
|
if(quotient) return false; /* added */
|
2020-01-26 00:23:10 +00:00
|
|
|
auto mr = dynamic_cast<hrmap_reg3_rule*> (currentmap);
|
|
|
|
if(mr) {
|
2020-01-28 12:02:39 +00:00
|
|
|
if(geometry == gSpace535)
|
|
|
|
return c->master->fieldval % 31 == 0;
|
2020-01-26 00:23:10 +00:00
|
|
|
return c->master->fieldval == 0;
|
|
|
|
}
|
|
|
|
if(m && hyperbolic) {
|
2019-03-09 00:00:46 +00:00
|
|
|
heptagon *h = m->reg_gmatrix[c->master].first;
|
2019-03-02 23:43:31 +00:00
|
|
|
return (h->zebraval == 1) && (h->distance & 1);
|
|
|
|
}
|
2020-01-26 00:23:10 +00:00
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-12 09:22:13 +00:00
|
|
|
EX void generate_cellrotations() {
|
|
|
|
auto &cr = cgi.cellrotations;
|
|
|
|
if(isize(cr)) return;
|
|
|
|
|
|
|
|
for(int a=0; a<S7; a++)
|
|
|
|
for(int b=0; b<S7; b++)
|
|
|
|
for(int c=0; c<S7; c++) {
|
2020-04-05 08:53:34 +00:00
|
|
|
transmatrix T = build_matrix(cgi.adjmoves[a]*C0, cgi.adjmoves[b]*C0, cgi.adjmoves[c]*C0, C0);
|
2019-10-12 09:22:13 +00:00
|
|
|
if(abs(det(T)) < 0.001) continue;
|
2020-04-05 08:53:34 +00:00
|
|
|
transmatrix U = build_matrix(cgi.adjmoves[0]*C0, cgi.adjmoves[1]*C0, cgi.adjmoves[2]*C0, C0);
|
2019-10-12 09:22:13 +00:00
|
|
|
transmatrix S = U * inverse(T);
|
|
|
|
if(abs(det(S) - 1) > 0.01) continue;
|
|
|
|
vector<int> perm(S7);
|
|
|
|
for(int x=0; x<S7; x++) perm[x] = -1;
|
|
|
|
for(int x=0; x<S7; x++)
|
|
|
|
for(int y=0; y<S7; y++)
|
2020-04-05 08:53:34 +00:00
|
|
|
if(hdist(S * cgi.adjmoves[x] * C0, cgi.adjmoves[y] * C0) < .1) perm[x] = y;
|
2019-10-12 09:22:13 +00:00
|
|
|
bool bad = false;
|
|
|
|
for(int x=0; x<S7; x++) if(perm[x] == -1) bad = true;
|
|
|
|
if(bad) continue;
|
|
|
|
|
2020-01-28 14:15:35 +00:00
|
|
|
cr.emplace_back(geometry_information::cellrotation_t{S, perm, 0});
|
2019-10-12 09:22:13 +00:00
|
|
|
}
|
2020-01-28 14:15:35 +00:00
|
|
|
|
|
|
|
int rots = isize(cr);
|
|
|
|
for(int i=0; i<rots; i++)
|
|
|
|
for(int j=0; j<rots; j++)
|
|
|
|
if(cr[i].mapping[cr[j].mapping[0]] == 0 && cr[i].mapping[cr[j].mapping[1]] == 1 && cr[i].mapping[cr[j].mapping[2]] == 2)
|
|
|
|
cr[i].inverse_id = j;
|
2019-10-12 09:22:13 +00:00
|
|
|
}
|
2019-10-12 17:09:53 +00:00
|
|
|
#endif
|
2019-10-12 09:22:13 +00:00
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
#if 0
|
|
|
|
/* More precise, but very slow distance. Not used/optimized for now */
|
|
|
|
|
|
|
|
ld adistance(cell *c) {
|
|
|
|
hyperpoint h = tC0(regmap()->reg_gmatrix[c->master].second);
|
2019-12-14 11:05:01 +00:00
|
|
|
h = bt::deparabolic3(h);
|
2019-03-02 23:43:31 +00:00
|
|
|
return regmap()->reg_gmatrix[c->master].first->distance * log(2) - h[0];
|
|
|
|
}
|
|
|
|
|
Remove USE_UNORDERED_MAP because it has bit-rotted.
Trying to compile with `-DUSE_UNORDERED_MAP` produces lots of compiler errors
like these, because of missing `std::hash` specializations.
Also, `#define unordered_map map` is just evil!
```
./nonisotropic.cpp:875:36: note: in instantiation of template class 'std::__1::unordered_map<hr::nilv::mvec, hr::heptagon *,
std::__1::hash<hr::nilv::mvec>, std::__1::equal_to<hr::nilv::mvec>, std::__1::allocator<std::__1::pair<const hr::nilv::mvec, hr::heptagon
*> > >' requested here
unordered_map<mvec, heptagon*> at;
^
./nonisotropic.cpp:239:58: note: in instantiation of template class 'std::__1::unordered_map<std::__1::pair<hr::heptagon *, hr::heptagon *>,
hr::heptagon *, std::__1::hash<std::__1::pair<hr::heptagon *, hr::heptagon *> >, std::__1::equal_to<std::__1::pair<hr::heptagon *,
hr::heptagon *> >, std::__1::allocator<std::__1::pair<const std::__1::pair<hr::heptagon *, hr::heptagon *>, hr::heptagon *> > >'
requested here
unordered_map<pair<heptagon*, heptagon*>, heptagon*> at;
^
./nonisotropic.cpp:457:49: error: no matching member function for call to 'iadj'
while(h1->distance < h2->distance) back = iadj(h2, down) * back, h2 = h2->cmove(down);
^~~~
cell.cpp:42:15: note: candidate function not viable: no known conversion from 'hr::sn::hrmap_solnih' to 'hr::hrmap' for object argument
transmatrix iadj(heptagon *h, int d) {
^
cell.cpp:41:22: note: candidate function not viable: no known conversion from 'hr::sn::hrmap_solnih' to 'hr::hrmap' for object argument
struct transmatrix iadj(cell *c, int i) { cell *c1 = c->cmove(i); return adj(c1, c->c.spin(i)); }
^
```
2020-09-25 03:15:19 +00:00
|
|
|
map<pair<cell*, cell*>, int> memo;
|
2019-03-02 23:43:31 +00:00
|
|
|
|
|
|
|
bool cdd;
|
|
|
|
|
|
|
|
int celldistance(cell *c1, cell *c2) {
|
|
|
|
if(memo.count(make_pair(c1, c2))) return memo[make_pair(c1, c2)];
|
|
|
|
if(c1 == c2) return 0;
|
|
|
|
vector<cell*> v[2];
|
|
|
|
v[0].push_back(c1);
|
|
|
|
v[1].push_back(c2);
|
|
|
|
|
|
|
|
int steps = 0;
|
|
|
|
|
|
|
|
map<cell*, int> visited;
|
|
|
|
visited[c1] = 1;
|
|
|
|
visited[c2] = 2;
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
if(cdd) {
|
|
|
|
println(hlog, "state ", steps, "/",isize(v[0]), "/", isize(v[1]));
|
|
|
|
println(hlog, " A: ", v[0]);
|
|
|
|
println(hlog, " B: ", v[1]);
|
|
|
|
}
|
|
|
|
for(int i: {0,1}) {
|
|
|
|
vector<cell*> new_v;
|
|
|
|
for(cell *c: v[i]) forCellCM(cn, c) if(adistance(cn) < adistance(c)) {
|
|
|
|
auto &vi = visited[cn];
|
|
|
|
if((vi&3) == 0) {
|
|
|
|
vi = 4 * (steps+1);
|
|
|
|
vi |= (1<<i);
|
|
|
|
new_v.push_back(cn);
|
|
|
|
}
|
|
|
|
else if((vi&3) == 2-i) {
|
|
|
|
vector<pair<cell*, int>> ca1, ca2;
|
|
|
|
int b1 = 4*steps-4;
|
|
|
|
int b2 = ((vi>>2)<<2) - 4;
|
|
|
|
for(auto p: visited) {
|
|
|
|
if(cdd) println(hlog, p);
|
|
|
|
int ps = p.second & 3;
|
|
|
|
if(ps == 1+i && p.second >= b1)
|
|
|
|
ca1.emplace_back(p.first, p.second/4);
|
|
|
|
if(ps == 2-i && p.second >= b2 && p.second <= b2+8)
|
|
|
|
ca2.emplace_back(p.first, p.second/4);
|
|
|
|
}
|
|
|
|
int bound = 1<<16;
|
|
|
|
for(auto p1: ca1) for(auto p2: ca2) {
|
|
|
|
hyperpoint h = tC0(relative_matrix(p1.first->master, p2.first->master));
|
|
|
|
int b = bucketer(h);
|
|
|
|
if(close_distances.count(b)) {
|
|
|
|
int d = close_distances[b] + p1.second + p2.second;
|
|
|
|
if(cdd) println(hlog, "candidate: close=", close_distances[b], p1, p2, "; h = ", h);
|
|
|
|
if(d < bound) bound = d;
|
|
|
|
}
|
|
|
|
else if(cdd) println(hlog, "bucket missing");
|
|
|
|
}
|
|
|
|
return memo[make_pair(c1, c2)] = bound;
|
|
|
|
return bound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v[i] = std::move(new_v);
|
|
|
|
}
|
|
|
|
steps++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cellwalker target;
|
|
|
|
int tsteps;
|
|
|
|
|
|
|
|
int dist_alt(cell *c) {
|
|
|
|
if(!target.at) {
|
|
|
|
target = cellwalker(currentmap->gamestart(), 0);
|
|
|
|
tsteps = 0;
|
|
|
|
for(int i=0; i<30; i++) target += wstep, target += rev, tsteps++;
|
|
|
|
}
|
|
|
|
if(specialland == laCamelot) return reg3::celldistance(c, target.at);
|
|
|
|
else {
|
|
|
|
int d = reg3::celldistance(c, target.at) - tsteps;
|
|
|
|
if(d < 10) target += wstep, target += rev, tsteps++;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-03-10 17:37:09 +00:00
|
|
|
// Construct a cellwalker in direction j from cw.at, such that its direction is as close
|
|
|
|
// as possible to cw.spin. Assume that j and cw.spin are adjacent
|
|
|
|
|
2019-05-06 23:08:49 +00:00
|
|
|
#if MAXMDIM >= 4
|
2019-08-09 20:37:11 +00:00
|
|
|
EX cellwalker strafe(cellwalker cw, int j) {
|
2020-04-05 08:53:34 +00:00
|
|
|
hyperpoint hfront = tC0(cgi.adjmoves[cw.spin]);
|
2020-04-21 23:45:04 +00:00
|
|
|
cw.at->cmove(j);
|
2019-11-14 15:51:50 +00:00
|
|
|
transmatrix T = currentmap->adj(cw.at, j);
|
2019-03-10 17:37:09 +00:00
|
|
|
for(int i=0; i<S7; i++) if(i != cw.at->c.spin(j))
|
2020-04-05 08:53:34 +00:00
|
|
|
if(hdist(hfront, T * tC0(cgi.adjmoves[i])) < cgi.strafedist + .01)
|
2020-01-16 15:49:52 +00:00
|
|
|
return cellwalker(cw.at->cmove(j), i);
|
2019-03-10 17:37:09 +00:00
|
|
|
println(hlog, "incorrect strafe");
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-01-15 16:58:41 +00:00
|
|
|
|
|
|
|
EX int matrix_order(const transmatrix A) {
|
|
|
|
transmatrix T = A;
|
|
|
|
int res = 1;
|
|
|
|
while(!eqmatrix(T, Id)) {
|
|
|
|
res++; T = T * A;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-01-26 00:18:30 +00:00
|
|
|
EX void generate_fulls() {
|
|
|
|
reg3::generate_cellrotations();
|
|
|
|
|
|
|
|
auto cons = [&] (int i0, int i1, int i2) {
|
2020-04-05 08:53:34 +00:00
|
|
|
transmatrix T = build_matrix(cgi.adjmoves[ 0]*C0, cgi.adjmoves[ 1]*C0, cgi.adjmoves[ 2]*C0, C0);
|
|
|
|
transmatrix U = build_matrix(cgi.adjmoves[i0]*C0, cgi.adjmoves[i1]*C0, cgi.adjmoves[i2]*C0, C0);
|
2020-01-26 00:18:30 +00:00
|
|
|
return U * inverse(T);
|
|
|
|
};
|
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
cgi.full_P = cgi.adjmoves[0];
|
2020-05-26 22:54:15 +00:00
|
|
|
cgi.full_R = S7 == 8 ? cons(1, 7, 0) : S7 == 20 ? cons(1,2,6) : cons(1, 2, 0);
|
|
|
|
cgi.full_X = S7 == 8 ? cons(1, 0, 6) : S7 == 6 ? cons(1, 0, 5) : S7 == 20 ? cons(1,0,7) : cons(1, 0, cgi.face);
|
2020-01-26 00:18:30 +00:00
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
cgi.xp_order = matrix_order(cgi.full_X * cgi.full_P);
|
|
|
|
cgi.r_order = matrix_order(cgi.full_R);
|
|
|
|
cgi.rx_order = matrix_order(cgi.full_R * cgi.full_X);
|
|
|
|
println(hlog, "orders = ", tie(cgi.rx_order, cgi.r_order, cgi.xp_order));
|
2020-01-26 00:18:30 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 16:58:41 +00:00
|
|
|
EX void construct_relations() {
|
2020-04-05 08:53:34 +00:00
|
|
|
auto& rels = cgi.rels;
|
|
|
|
if(!rels.empty()) return;
|
2020-01-15 16:58:41 +00:00
|
|
|
rels.clear();
|
|
|
|
|
|
|
|
reg3::generate_cellrotations();
|
2020-01-26 00:18:30 +00:00
|
|
|
reg3::generate_fulls();
|
2020-01-15 16:58:41 +00:00
|
|
|
vector<transmatrix> all;
|
|
|
|
|
|
|
|
vector<string> formulas;
|
|
|
|
|
|
|
|
formulas.push_back("");
|
|
|
|
|
|
|
|
all.push_back(Id);
|
2021-03-25 10:12:58 +00:00
|
|
|
hyperpoint v = cgi.cellshape[0][0];
|
2020-01-15 16:58:41 +00:00
|
|
|
auto add = [&] (transmatrix T) {
|
|
|
|
for(int i=0; i<isize(all); i++) if(eqmatrix(all[i], T)) return i;
|
|
|
|
int S = isize(all);
|
|
|
|
all.push_back(T);
|
|
|
|
return S;
|
|
|
|
};
|
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
println(hlog, cgi.cellshape);
|
2020-01-15 16:58:41 +00:00
|
|
|
|
2020-04-05 08:53:34 +00:00
|
|
|
println(hlog, "cellshape = ", isize(cgi.cellshape));
|
2020-01-15 16:58:41 +00:00
|
|
|
bool ok = true;
|
|
|
|
int last_i = -1;
|
2021-03-25 10:12:58 +00:00
|
|
|
for(auto& v: cgi.cellshape) for(hyperpoint h: v) {
|
2020-01-15 16:58:41 +00:00
|
|
|
int i = 0, j = 0;
|
2021-03-25 10:12:58 +00:00
|
|
|
for(auto& uv: cgi.cellshape) for(hyperpoint u: uv) {
|
|
|
|
if(hdist(h, cgi.full_X*u) < 5e-2) i++;
|
|
|
|
if(hdist(h, cgi.full_R*u) < 5e-2) j++;
|
|
|
|
}
|
2020-01-15 16:58:41 +00:00
|
|
|
if(last_i == -1) last_i = i;
|
|
|
|
if(i != j || i != last_i) ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ok) { println(hlog, "something wrong"); exit(1); }
|
|
|
|
|
|
|
|
add(Id);
|
|
|
|
|
|
|
|
auto work = [&] (transmatrix T, int p, char c) {
|
|
|
|
if(hdist0(tC0(T)) > 5) return;
|
2021-03-25 10:12:58 +00:00
|
|
|
for(auto& hv: cgi.cellshape) for(hyperpoint h: hv) if(hdist(T * h, v) < 1e-4) goto ok;
|
2020-01-15 16:58:41 +00:00
|
|
|
return;
|
|
|
|
ok:
|
|
|
|
int id = add(T);
|
|
|
|
// println(hlog, p, " x ", (s0+c), " = ", id);
|
|
|
|
|
|
|
|
if(id >= isize(formulas)) formulas.push_back(formulas[p] + c);
|
|
|
|
else if(id == 0) println(hlog, "reached identity: ", formulas[p]+c);
|
|
|
|
else if(formulas[p][0] != formulas[id][0])
|
|
|
|
rels.emplace_back(formulas[p] + c, formulas[id]);
|
|
|
|
};
|
|
|
|
|
|
|
|
for(int i=0; i<isize(all); i++) {
|
|
|
|
transmatrix T = all[i];
|
2020-04-05 08:53:34 +00:00
|
|
|
work(T * cgi.full_R, i, 'R');
|
|
|
|
work(T * cgi.full_X, i, 'X');
|
|
|
|
work(T * cgi.full_P, i, 'P');
|
2020-01-26 00:18:30 +00:00
|
|
|
}
|
2020-01-15 16:58:41 +00:00
|
|
|
}
|
|
|
|
|
2019-09-12 22:31:32 +00:00
|
|
|
EX }
|
2019-05-06 23:08:49 +00:00
|
|
|
#endif
|
2020-05-22 14:52:46 +00:00
|
|
|
|
|
|
|
#if MAXMDIM == 3
|
|
|
|
EX namespace reg3 {
|
2020-05-22 18:38:13 +00:00
|
|
|
EX bool in() { return false; }
|
2020-07-05 12:02:28 +00:00
|
|
|
EX bool in_rule() { return false; }
|
2020-05-22 14:52:46 +00:00
|
|
|
EX }
|
|
|
|
#endif
|
|
|
|
|
2019-03-02 23:43:31 +00:00
|
|
|
}
|
|
|
|
|