From c7cb93f2edac7c53e52a222d7b262de9a40d22b9 Mon Sep 17 00:00:00 2001 From: ? Date: Sun, 24 Feb 2019 23:04:52 +0100 Subject: [PATCH] moved all the Euclidean maps to euclid.cpp --- cell.cpp | 462 +---------------------------------------------- compileunits.h | 2 +- euclid.cpp | 479 ++++++++++++++++++++++++++++++++++++++++++++++++- geometry2.cpp | 2 +- graph.cpp | 2 +- heptagon.cpp | 2 +- hyper.h | 2 +- hypgraph.cpp | 2 +- 8 files changed, 479 insertions(+), 474 deletions(-) diff --git a/cell.cpp b/cell.cpp index b9772299..453e947e 100644 --- a/cell.cpp +++ b/cell.cpp @@ -245,464 +245,6 @@ heptagon *getDodecahedron(int i) { return s->dodecahedron[i]; } -// --- euclidean geometry --- - -// NOTE: patterns assume that pair_to_vec(0,1) % 3 == 2! -// Thus, pair_to_vec(0,1) must not be e.g. a power of four - -int pair_to_vec(int x, int y) { - return x + (y << 15); - } - -pair vec_to_pair(int vec) { - int x = vec & ((1<<15)-1); - int y = (vec >> 15); - if(x >= (1<<14)) x -= (1<<15), y++; - return {x, y}; - } - -namespace torusconfig { - // the configuration of the torus topology. - // torus cells are indexed [0..qty), - // where the cell to the right from i is indexed i+dx, - // and the cell to the down-right is numbered i+dy - - // Changed with command line option: -tpar ,, - // Ideally, qty, dx, and dy should have the same "modulo 3" - // values as the default -- otherwise the three-color - // pattern breaks. Also, they should have no common - // prime divisor. - int def_qty = 127*3, dx = 1, def_dy = -11*2; - int qty = def_qty, dy = def_dy; - - int sdx = 12, sdy = 12; - - // new values to change - int newqty, newdy, newsdx, newsdy; - int torus_cx, torus_cy; - - vector tmodes = { - {"single row (hex)", TF_SINGLE | TF_HEX}, - {"single row (squares)", TF_SINGLE | TF_SQUARE}, - {"parallelogram (hex)", TF_SIMPLE | TF_HEX}, - {"rectangle (squares)", TF_SIMPLE | TF_SQUARE}, - {"rectangle (hex)", TF_WEIRD | TF_HEX}, - {"Klein bottle (squares)", TF_SIMPLE | TF_KLEIN | TF_SQUARE}, - {"Klein bottle (hex)", TF_WEIRD | TF_KLEIN | TF_HEX}, - {"cylinder (squares)", TF_SIMPLE | TF_CYL }, - {"cylinder (hex)", TF_SIMPLE | TF_CYL | TF_HEX}, - {"Möbius band (squares)", TF_SIMPLE | TF_CYL | TF_KLEIN}, - {"Möbius band (hex)", TF_SIMPLE | TF_CYL | TF_HEX | TF_KLEIN}, - }; - - eTorusMode torus_mode, newmode; - flagtype tmflags() { return tmodes[torus_mode].flags; } - - int getqty() { - if(tmflags() & TF_SINGLE) - return qty; - else - return sdx * sdy; - } - - int getvec(int x, int y) { - if(tmflags() & TF_SINGLE) - return x * dx + y * dy; - else if(tmflags() & TF_SIMPLE) - return pair_to_vec(x, y); - else - return pair_to_vec(-y - 2 * x, 3 * y); - } - - int id_to_vec(int id, bool mirrored = false) { - if(tmflags() & TF_SINGLE) - return id; - else { - int dx = id % sdx; - int dy = id / sdx; - if(mirrored) - dy = -dy, dx += sdx; - if(tmflags() & TF_SIMPLE) - return pair_to_vec(dx, dy); - else - return pair_to_vec(- 2 * dx - (dy & 1), 3 * dy); - } - } - - pair vec_to_id_mirror(int vec) { - if(tmflags() & TF_SINGLE) { - return {gmod(vec, qty), false}; - } - else { - int x, y; - tie(x,y) = vec_to_pair(vec); - bool mirror = false; - if(tmflags() & TF_KLEIN) { - if(tmflags() & TF_WEIRD) { - x = gmod(x, 4 * sdx); - mirror = x > 0 && x <= 2 * sdx; - } - else { - x = gmod(x, 2 * sdx); - mirror = x >= sdx; - } - if(mirror) y = -y; - } - if(tmflags() & TF_WEIRD) { - y /= 3; x = (x + (y&1)) / -2; - } - x = gmod(x, sdx), y = gmod(y, sdy); - return {y * sdx + x, mirror}; - } - } - - int vec_to_id(int vec) { - return vec_to_id_mirror(vec).first; - } - - void torus_test() { - printf("Testing torus vec_to_pair/pair_to_vec...\n"); - for(int x=-10; x<=10; x++) - for(int y=-10; y<=10; y++) { - auto p = vec_to_pair(pair_to_vec(x, y)); - if(p.first != x || p.second != y) - printf("Failed for (%d,%d) -> [%d] -> (%d,%d)\n", x, y, pair_to_vec(x,y), p.first, p.second); - } - printf("Testing id_to_vec / vec_to_id...\n"); - for(int i=0; i < getqty(); i++) - for(int m=0; m< (torus_mode == tmKlein ? 2 : 1); m++) - if(vec_to_id_mirror(id_to_vec(i, m)) != pair (i,m)) - printf("Failed for id %d.%d [%d] (%d.%d)\n", i, m, id_to_vec(i,m), vec_to_id(id_to_vec(i,m)), vec_to_id_mirror(id_to_vec(i,m)).second); - } - - int tester = addHook(hooks_tests, 0, torus_test); - - void activate() { - auto& gi(ginf[gTorus]); - - if(tmflags() & TF_HEX) - gi.vertex = 3, gi.sides = 6, gi.tiling_name = "{6,3}"; - else - gi.vertex = 4, gi.sides = 4, gi.tiling_name = "{4,4}"; - - flagtype& flags = gi.flags; - - set_flag(flags, qNONORIENTABLE, tmflags() & TF_KLEIN); - set_flag(flags, qBOUNDED, !(tmflags() & TF_CYL)); - - int i = 0; - if(tmflags() & TF_KLEIN) i++; - if(tmflags() & TF_CYL) i+=2; - - const char *quonames[4] = {"torus", "Klein bottle", "cylinder", "Möbius band"}; - gi.quotient_name = quonames[i]; - } - - 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); - } - - int dcross(gp::loc e1, gp::loc e2) { - return e1.first * e2.second - e1.second*e2.first; - } - - gp::loc sdxy() { return gp::loc(sdx, sdy); } - - int mobius_dir_basic() { - int dscalars[6]; - for(int a=0; a g(geometry, square ? gEuclidSquare : gEuclid); - dynamicval gx(sdx, dx); - dynamicval gy(sdy, dy); - return mobius_dir_basic() != -1; - } - - void mobius_flip(int&x, int& y) { - - int d = mobius_dir_basic(); - int a, b; - if(d == 0) a = 1, b = SG6-1; - else a = 0, b = d; - auto p1 = gp::eudir(a); - auto p2 = gp::eudir(b); - - // x = sdx * s + px * t - // y = sdy * s + py * t - // py * x = py * sdx * s + px * py * t - // px * y = px * sdy * s + px + py * t - // py * x - px * y = py * sdx * s - px * sdy * s - // s = (py * x - px * y) / (py * sdx - px * sdy) - - int det = p1.second * sdx - p1.first * sdy; - int smul = p1.second * x - p1.first * y; - int tmul = sdx * y - sdy * x; - - x = (tmul * p2.first + smul * sdx) / det; - y = (tmul * p2.second + smul * sdy) / det; - - // println(hlog, make_pair(ox,oy), " [", d, "] ", make_pair(x,y), " p1 = ", p1, " p2 = ", p2, " det = ", det, " smul = ", smul, " tmul = ", tmul); - } - - int mobius_dir(cell *c) { - if(c->type == 8) return mobius_dir_basic() * 2; - else return mobius_dir_basic(); - } - - bool be_canonical(int& x, int& y) { - using namespace torusconfig; - - int periods = gdiv(dscalar(gp::loc(x,y), sdxy()), dscalar(sdxy(), sdxy())); - - y -= sdy * periods; - x -= sdx * periods; - - bool b = false; - - if(nonorientable && (periods & 1)) { - mobius_flip(x, y); - b = true; - } - - return b; - } - - int cyldist(int id1, int id2) { - - int x1, y1, x2, y2; - tie(x1, y1) = vec_to_pair(id1); - tie(x2, y2) = vec_to_pair(id2); - be_canonical(x1, y1); - be_canonical(x2, y2); - - int dist = 1000000000; - - for(int a1=-1; a1<=1; a1++) - for(int a2=-1; a2<=1; a2++) { - int ax1 = x1 + sdx * a1; - int ay1 = y1 + sdy * a1; - if(nonorientable && a1) mobius_flip(ax1, ay1); - int ax2 = x2 + sdx * a2; - int ay2 = y2 + sdy * a2; - if(nonorientable && a2) mobius_flip(ax2, ay2); - dist = min(dist, eudist(ax1 - ax2, ay1 - ay2)); - - } - - return dist; - } - } - -int euclid_getvec(int dx, int dy) { - if(euwrap) return torusconfig::getvec(dx, dy); - else return pair_to_vec(dx, dy); - } - -template void build_euclidean_moves(cell *c, int vec, const T& builder) { - int x, y; - tie(x,y) = vec_to_pair(vec); - c->type = a4 ? (PURE || ((x^y^1) & 1) ? 4 : 8) : 6; - - if(c->type == 4) { - int m = PURE ? 1 : 2; - builder(euclid_getvec(+1,+0), 0, 2 * m); - builder(euclid_getvec(+0,+1), 1, 3 * m); - builder(euclid_getvec(-1,+0), 2, 0 * m); - builder(euclid_getvec(+0,-1), 3, 1 * m); - } - else if(c->type == 8) { - builder(euclid_getvec(+1,+0), 0, 2); - builder(euclid_getvec(+1,+1), 1, 5); - builder(euclid_getvec(+0,+1), 2, 3); - builder(euclid_getvec(-1,+1), 3, 7); - builder(euclid_getvec(-1,+0), 4, 0); - builder(euclid_getvec(-1,-1), 5, 1); - builder(euclid_getvec(+0,-1), 6, 1); - builder(euclid_getvec(+1,-1), 7, 3); - } - else /* 6 */ { - builder(euclid_getvec(+1,+0), 0, 3); - builder(euclid_getvec(+0,+1), 1, 4); - builder(euclid_getvec(-1,+1), 2, 5); - builder(euclid_getvec(-1,+0), 3, 0); - builder(euclid_getvec(+0,-1), 4, 1); - builder(euclid_getvec(+1,-1), 5, 2); - } - } - -struct hrmap_torus : hrmap { - - vector all; - vector dists; - - virtual vector& allcells() { return all; } - - cell *gamestart() { - return all[0]; - } - - hrmap_torus() { - using namespace torusconfig; - int q = getqty(); - all.resize(q); - for(int i=0; imove(d) = all[im.first]; - all[i]->c.setspin(d, im.second, false); - }); - } - for(cell *c: all) for(int d=0; dtype; d++) { - cell *c2 = c->move(d); - for(int d2=0; d2type; d2++) - if(c2->move(d2) == c) - c->c.setspin(d, d2, c->c.spin(d)); - } - celllister cl(gamestart(), 100, 100000000, NULL); - dists.resize(q); - for(int i=0; imaster)] = cl.dists[i]; - } - - ~hrmap_torus() { - for(cell *c: all) tailored_delete(c); - } - }; - -hrmap_torus *torusmap() { - return dynamic_cast (currentmap); - } - -/* cell *getTorusId(int id) { - hrmap_torus *cur = torusmap(); - if(!cur) return NULL; - return cur->all[id]; - } */ - -struct hrmap_euclidean : hrmap { - - cell *gamestart() { - return *(euclideanAtCreate(0).first); - } - - struct euclideanSlab { - cell* a[256][256]; - euclideanSlab() { - for(int y=0; y<256; y++) for(int x=0; x<256; x++) - a[y][x] = NULL; - } - ~euclideanSlab() { - for(int y=0; y<256; y++) for(int x=0; x<256; x++) - if(a[y][x]) tailored_delete(a[y][x]); - } - }; - - static const int slabs = max_vec / 256; - - euclideanSlab* euclidean[slabs][slabs]; - - hrmap_euclidean() { - for(int y=0; y>8)&(slabs-1)][(x>>8)&(slabs-1)]; - if(!slab) slab = new hrmap_euclidean::euclideanSlab; - return make_pair(&(slab->a[y&255][x&255]), mobius); - } - - map eucdata; - - ~hrmap_euclidean() { - for(int y=0; yall[p.first], 0, p.second); - } - } - -int cellwalker_to_vec(cellwalker cw) { - int id = decodeId(cw.at->master); - if(!fulltorus) { - if(nonorientable) { - auto ep = euclideanAt(id); - if(ep.second != cw.mirrored) { - int x, y; - tie(x, y) = vec_to_pair(id); - x += torusconfig::sdx; - y += torusconfig::sdy; - torusconfig::mobius_flip(x, y); - return pair_to_vec(x, y); - } - } - return id; - } - return torusconfig::id_to_vec(id, cw.mirrored); - } - -int cell_to_vec(cell *c) { - int id = decodeId(c->master); - if(!fulltorus) return id; - return torusconfig::id_to_vec(id, false); - } - -pair cell_to_pair(cell *c) { - return vec_to_pair(cell_to_vec(c)); - } - -union heptacoder { - heptagon *h; - int id; - }; - -int decodeId(heptagon* h) { - heptacoder u; - u.h = h; return u.id; - } - -heptagon* encodeId(int id) { - heptacoder u; - u.id = id; - return u.h; - } - // --- quotient geometry --- namespace quotientspace { @@ -1236,7 +778,7 @@ void initcells() { else if(archimedean) currentmap = arcm::new_map(); #endif else if(fulltorus) currentmap = new hrmap_torus; - else if(euclid && DIM == 3) currentmap = space::new_map(); + else if(euclid && DIM == 3) currentmap = euclid3::new_map(); else if(euclid) currentmap = new hrmap_euclidean; else if(sphere) currentmap = new hrmap_spherical; else if(quotient) currentmap = new quotientspace::hrmap_quotient; @@ -1873,7 +1415,7 @@ int celldistance(cell *c1, cell *c2) { return binary::celldistance3(c1, c2); if(euclid && DIM == 3) - return space::celldistance(c1, c2); + return euclid3::celldistance(c1, c2); return hyperbolic_celldistance(c1, c2); } diff --git a/compileunits.h b/compileunits.h index 0313b66b..cdc14696 100644 --- a/compileunits.h +++ b/compileunits.h @@ -31,7 +31,7 @@ #include "heptagon.cpp" #include "binary-tiling.cpp" #include "archimedean.cpp" -#include "space.cpp" +#include "euclid.cpp" #include "crystal.cpp" #include "language.cpp" #include "cell.cpp" diff --git a/euclid.cpp b/euclid.cpp index c8699a91..a4e523db 100644 --- a/euclid.cpp +++ b/euclid.cpp @@ -1,17 +1,480 @@ -// Hyperbolic Rogue -- euclidean 3D geometry +// Hyperbolic Rogue -- Euclidean geometry, including 2D, 3D, and quotient spaces // Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details namespace hr { -#if DIM == 3 -namespace space { +// 2D Euclidean space + +// --- euclidean geometry --- + +// NOTE: patterns assume that pair_to_vec(0,1) % 3 == 2! +// Thus, pair_to_vec(0,1) must not be e.g. a power of four + +int pair_to_vec(int x, int y) { + return x + (y << 15); + } + +pair vec_to_pair(int vec) { + int x = vec & ((1<<15)-1); + int y = (vec >> 15); + if(x >= (1<<14)) x -= (1<<15), y++; + return {x, y}; + } + +namespace torusconfig { + // the configuration of the torus topology. + // torus cells are indexed [0..qty), + // where the cell to the right from i is indexed i+dx, + // and the cell to the down-right is numbered i+dy + + // Changed with command line option: -tpar ,, + // Ideally, qty, dx, and dy should have the same "modulo 3" + // values as the default -- otherwise the three-color + // pattern breaks. Also, they should have no common + // prime divisor. + int def_qty = 127*3, dx = 1, def_dy = -11*2; + int qty = def_qty, dy = def_dy; + + int sdx = 12, sdy = 12; + + // new values to change + int newqty, newdy, newsdx, newsdy; + int torus_cx, torus_cy; + + vector tmodes = { + {"single row (hex)", TF_SINGLE | TF_HEX}, + {"single row (squares)", TF_SINGLE | TF_SQUARE}, + {"parallelogram (hex)", TF_SIMPLE | TF_HEX}, + {"rectangle (squares)", TF_SIMPLE | TF_SQUARE}, + {"rectangle (hex)", TF_WEIRD | TF_HEX}, + {"Klein bottle (squares)", TF_SIMPLE | TF_KLEIN | TF_SQUARE}, + {"Klein bottle (hex)", TF_WEIRD | TF_KLEIN | TF_HEX}, + {"cylinder (squares)", TF_SIMPLE | TF_CYL }, + {"cylinder (hex)", TF_SIMPLE | TF_CYL | TF_HEX}, + {"Möbius band (squares)", TF_SIMPLE | TF_CYL | TF_KLEIN}, + {"Möbius band (hex)", TF_SIMPLE | TF_CYL | TF_HEX | TF_KLEIN}, + }; + + eTorusMode torus_mode, newmode; + flagtype tmflags() { return tmodes[torus_mode].flags; } + + int getqty() { + if(tmflags() & TF_SINGLE) + return qty; + else + return sdx * sdy; + } + + int getvec(int x, int y) { + if(tmflags() & TF_SINGLE) + return x * dx + y * dy; + else if(tmflags() & TF_SIMPLE) + return pair_to_vec(x, y); + else + return pair_to_vec(-y - 2 * x, 3 * y); + } + + int id_to_vec(int id, bool mirrored = false) { + if(tmflags() & TF_SINGLE) + return id; + else { + int dx = id % sdx; + int dy = id / sdx; + if(mirrored) + dy = -dy, dx += sdx; + if(tmflags() & TF_SIMPLE) + return pair_to_vec(dx, dy); + else + return pair_to_vec(- 2 * dx - (dy & 1), 3 * dy); + } + } + + pair vec_to_id_mirror(int vec) { + if(tmflags() & TF_SINGLE) { + return {gmod(vec, qty), false}; + } + else { + int x, y; + tie(x,y) = vec_to_pair(vec); + bool mirror = false; + if(tmflags() & TF_KLEIN) { + if(tmflags() & TF_WEIRD) { + x = gmod(x, 4 * sdx); + mirror = x > 0 && x <= 2 * sdx; + } + else { + x = gmod(x, 2 * sdx); + mirror = x >= sdx; + } + if(mirror) y = -y; + } + if(tmflags() & TF_WEIRD) { + y /= 3; x = (x + (y&1)) / -2; + } + x = gmod(x, sdx), y = gmod(y, sdy); + return {y * sdx + x, mirror}; + } + } + + int vec_to_id(int vec) { + return vec_to_id_mirror(vec).first; + } + + void torus_test() { + printf("Testing torus vec_to_pair/pair_to_vec...\n"); + for(int x=-10; x<=10; x++) + for(int y=-10; y<=10; y++) { + auto p = vec_to_pair(pair_to_vec(x, y)); + if(p.first != x || p.second != y) + printf("Failed for (%d,%d) -> [%d] -> (%d,%d)\n", x, y, pair_to_vec(x,y), p.first, p.second); + } + printf("Testing id_to_vec / vec_to_id...\n"); + for(int i=0; i < getqty(); i++) + for(int m=0; m< (torus_mode == tmKlein ? 2 : 1); m++) + if(vec_to_id_mirror(id_to_vec(i, m)) != pair (i,m)) + printf("Failed for id %d.%d [%d] (%d.%d)\n", i, m, id_to_vec(i,m), vec_to_id(id_to_vec(i,m)), vec_to_id_mirror(id_to_vec(i,m)).second); + } + + int tester = addHook(hooks_tests, 0, torus_test); + + void activate() { + auto& gi(ginf[gTorus]); + + if(tmflags() & TF_HEX) + gi.vertex = 3, gi.sides = 6, gi.tiling_name = "{6,3}"; + else + gi.vertex = 4, gi.sides = 4, gi.tiling_name = "{4,4}"; + + flagtype& flags = gi.flags; + + set_flag(flags, qNONORIENTABLE, tmflags() & TF_KLEIN); + set_flag(flags, qBOUNDED, !(tmflags() & TF_CYL)); + + int i = 0; + if(tmflags() & TF_KLEIN) i++; + if(tmflags() & TF_CYL) i+=2; + + const char *quonames[4] = {"torus", "Klein bottle", "cylinder", "Möbius band"}; + gi.quotient_name = quonames[i]; + } + + 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); + } + + int dcross(gp::loc e1, gp::loc e2) { + return e1.first * e2.second - e1.second*e2.first; + } + + gp::loc sdxy() { return gp::loc(sdx, sdy); } + + int mobius_dir_basic() { + int dscalars[6]; + for(int a=0; a g(geometry, square ? gEuclidSquare : gEuclid); + dynamicval gx(sdx, dx); + dynamicval gy(sdy, dy); + return mobius_dir_basic() != -1; + } + + void mobius_flip(int&x, int& y) { + + int d = mobius_dir_basic(); + int a, b; + if(d == 0) a = 1, b = SG6-1; + else a = 0, b = d; + auto p1 = gp::eudir(a); + auto p2 = gp::eudir(b); + + // x = sdx * s + px * t + // y = sdy * s + py * t + // py * x = py * sdx * s + px * py * t + // px * y = px * sdy * s + px + py * t + // py * x - px * y = py * sdx * s - px * sdy * s + // s = (py * x - px * y) / (py * sdx - px * sdy) + + int det = p1.second * sdx - p1.first * sdy; + int smul = p1.second * x - p1.first * y; + int tmul = sdx * y - sdy * x; + + x = (tmul * p2.first + smul * sdx) / det; + y = (tmul * p2.second + smul * sdy) / det; + + // println(hlog, make_pair(ox,oy), " [", d, "] ", make_pair(x,y), " p1 = ", p1, " p2 = ", p2, " det = ", det, " smul = ", smul, " tmul = ", tmul); + } + + int mobius_dir(cell *c) { + if(c->type == 8) return mobius_dir_basic() * 2; + else return mobius_dir_basic(); + } + + bool be_canonical(int& x, int& y) { + using namespace torusconfig; + + int periods = gdiv(dscalar(gp::loc(x,y), sdxy()), dscalar(sdxy(), sdxy())); + + y -= sdy * periods; + x -= sdx * periods; + + bool b = false; + + if(nonorientable && (periods & 1)) { + mobius_flip(x, y); + b = true; + } + + return b; + } + + int cyldist(int id1, int id2) { + + int x1, y1, x2, y2; + tie(x1, y1) = vec_to_pair(id1); + tie(x2, y2) = vec_to_pair(id2); + be_canonical(x1, y1); + be_canonical(x2, y2); + + int dist = 1000000000; + + for(int a1=-1; a1<=1; a1++) + for(int a2=-1; a2<=1; a2++) { + int ax1 = x1 + sdx * a1; + int ay1 = y1 + sdy * a1; + if(nonorientable && a1) mobius_flip(ax1, ay1); + int ax2 = x2 + sdx * a2; + int ay2 = y2 + sdy * a2; + if(nonorientable && a2) mobius_flip(ax2, ay2); + dist = min(dist, eudist(ax1 - ax2, ay1 - ay2)); + + } + + return dist; + } + } + +int euclid_getvec(int dx, int dy) { + if(euwrap) return torusconfig::getvec(dx, dy); + else return pair_to_vec(dx, dy); + } + +template void build_euclidean_moves(cell *c, int vec, const T& builder) { + int x, y; + tie(x,y) = vec_to_pair(vec); + c->type = a4 ? (PURE || ((x^y^1) & 1) ? 4 : 8) : 6; + + if(c->type == 4) { + int m = PURE ? 1 : 2; + builder(euclid_getvec(+1,+0), 0, 2 * m); + builder(euclid_getvec(+0,+1), 1, 3 * m); + builder(euclid_getvec(-1,+0), 2, 0 * m); + builder(euclid_getvec(+0,-1), 3, 1 * m); + } + else if(c->type == 8) { + builder(euclid_getvec(+1,+0), 0, 2); + builder(euclid_getvec(+1,+1), 1, 5); + builder(euclid_getvec(+0,+1), 2, 3); + builder(euclid_getvec(-1,+1), 3, 7); + builder(euclid_getvec(-1,+0), 4, 0); + builder(euclid_getvec(-1,-1), 5, 1); + builder(euclid_getvec(+0,-1), 6, 1); + builder(euclid_getvec(+1,-1), 7, 3); + } + else /* 6 */ { + builder(euclid_getvec(+1,+0), 0, 3); + builder(euclid_getvec(+0,+1), 1, 4); + builder(euclid_getvec(-1,+1), 2, 5); + builder(euclid_getvec(-1,+0), 3, 0); + builder(euclid_getvec(+0,-1), 4, 1); + builder(euclid_getvec(+1,-1), 5, 2); + } + } + +struct hrmap_torus : hrmap { + + vector all; + vector dists; + + virtual vector& allcells() { return all; } + + cell *gamestart() { + return all[0]; + } + + hrmap_torus() { + using namespace torusconfig; + int q = getqty(); + all.resize(q); + for(int i=0; imove(d) = all[im.first]; + all[i]->c.setspin(d, im.second, false); + }); + } + for(cell *c: all) for(int d=0; dtype; d++) { + cell *c2 = c->move(d); + for(int d2=0; d2type; d2++) + if(c2->move(d2) == c) + c->c.setspin(d, d2, c->c.spin(d)); + } + celllister cl(gamestart(), 100, 100000000, NULL); + dists.resize(q); + for(int i=0; imaster)] = cl.dists[i]; + } + + ~hrmap_torus() { + for(cell *c: all) tailored_delete(c); + } + }; + +hrmap_torus *torusmap() { + return dynamic_cast (currentmap); + } + +/* cell *getTorusId(int id) { + hrmap_torus *cur = torusmap(); + if(!cur) return NULL; + return cur->all[id]; + } */ + +struct hrmap_euclidean : hrmap { + + cell *gamestart() { + return *(euclideanAtCreate(0).first); + } + + struct euclideanSlab { + cell* a[256][256]; + euclideanSlab() { + for(int y=0; y<256; y++) for(int x=0; x<256; x++) + a[y][x] = NULL; + } + ~euclideanSlab() { + for(int y=0; y<256; y++) for(int x=0; x<256; x++) + if(a[y][x]) tailored_delete(a[y][x]); + } + }; + + static const int slabs = max_vec / 256; + + euclideanSlab* euclidean[slabs][slabs]; + + hrmap_euclidean() { + for(int y=0; y>8)&(slabs-1)][(x>>8)&(slabs-1)]; + if(!slab) slab = new hrmap_euclidean::euclideanSlab; + return make_pair(&(slab->a[y&255][x&255]), mobius); + } + + map eucdata; + + ~hrmap_euclidean() { + for(int y=0; yall[p.first], 0, p.second); + } + } + +int cellwalker_to_vec(cellwalker cw) { + int id = decodeId(cw.at->master); + if(!fulltorus) { + if(nonorientable) { + auto ep = euclideanAt(id); + if(ep.second != cw.mirrored) { + int x, y; + tie(x, y) = vec_to_pair(id); + x += torusconfig::sdx; + y += torusconfig::sdy; + torusconfig::mobius_flip(x, y); + return pair_to_vec(x, y); + } + } + return id; + } + return torusconfig::id_to_vec(id, cw.mirrored); + } + +int cell_to_vec(cell *c) { + int id = decodeId(c->master); + if(!fulltorus) return id; + return torusconfig::id_to_vec(id, false); + } + +pair cell_to_pair(cell *c) { + return vec_to_pair(cell_to_vec(c)); + } + +union heptacoder { + heptagon *h; + int id; + }; + +int decodeId(heptagon* h) { + heptacoder u; + u.h = h; return u.id; + } + +heptagon* encodeId(int id) { + heptacoder u; + u.id = id; + return u.h; + } + +// 3D Euclidean space + +#if MAXDIM == 4 + +namespace euclid3 { typedef long long coord; - struct hrmap_cube : hrmap { + struct hrmap_euclid3 : hrmap { map spacemap; map ispacemap; - hrmap_cube() { + hrmap_euclid3() { getOrigin(); } heptagon *getOrigin() { @@ -45,12 +508,12 @@ namespace space { } }; - hrmap_cube* cubemap() { - return ((hrmap_cube*) currentmap); + hrmap_euclid3* cubemap() { + return ((hrmap_euclid3*) currentmap); } hrmap* new_map() { - return new hrmap_cube; + return new hrmap_euclid3; } heptagon *createStep(heptagon *parent, int d) { diff --git a/geometry2.cpp b/geometry2.cpp index eff2585c..d3336108 100644 --- a/geometry2.cpp +++ b/geometry2.cpp @@ -93,7 +93,7 @@ transmatrix calc_relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hin if(binarytiling) return binary::relative_matrix(c2->master, c1->master); #endif #if MAXDIM == 4 - if(euclid && DIM == 3) return space::relative_matrix(c2->master, c1->master); + if(euclid && DIM == 3) return euclid3::relative_matrix(c2->master, c1->master); #endif #if CAP_ARCM if(archimedean) return arcm::relative_matrix(c2->master, c1->master); diff --git a/graph.cpp b/graph.cpp index a74af453..7b413a3c 100644 --- a/graph.cpp +++ b/graph.cpp @@ -5711,7 +5711,7 @@ void drawthemap() { #endif #if MAXDIM == 4 else if(euclid && DIM == 3) - space::draw(); + euclid3::draw(); #endif else drawStandard(); diff --git a/heptagon.cpp b/heptagon.cpp index dd00d8a9..a6df8a12 100644 --- a/heptagon.cpp +++ b/heptagon.cpp @@ -233,7 +233,7 @@ heptagon *createStep(heptagon *h, int d) { #endif #if MAXDIM == 4 if(!h->move(d) && euclid && DIM == 3) - return space::createStep(h, d); + return euclid3::createStep(h, d); #endif #if CAP_ARCM if(!h->move(d) && archimedean) { diff --git a/hyper.h b/hyper.h index 3746c87e..7fbb1110 100644 --- a/hyper.h +++ b/hyper.h @@ -4239,7 +4239,7 @@ namespace binary { #endif #if MAXDIM == 4 -namespace space { +namespace euclid3 { heptagon *createStep(heptagon *parent, int d); hrmap* new_map(); void draw(); diff --git a/hypgraph.cpp b/hypgraph.cpp index e49cfa18..ce1d5405 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -1118,7 +1118,7 @@ void optimizeview() { if(binarytiling) T = binary::relative_matrix(h2, viewctr.at); #endif #if MAXDIM == 4 - if(euclid && DIM == 3) T = space::relative_matrix(h2, viewctr.at); + if(euclid && DIM == 3) T = euclid3::relative_matrix(h2, viewctr.at); #endif #if CAP_ARCM if(archimedean) T = arcm::relative_matrix(h2, viewctr.at);