2018-11-07 00:53:10 +01:00
|
|
|
// show the fundamental domain for quotient spaces
|
|
|
|
// Copyright (C) 2018 Zeno and Tehora Rogue, see 'hyper.cpp' for details
|
|
|
|
|
2020-03-29 16:03:31 +02:00
|
|
|
#include "rogueviz.h"
|
|
|
|
|
2018-11-07 00:53:10 +01:00
|
|
|
namespace hr {
|
|
|
|
|
|
|
|
namespace fundamental {
|
|
|
|
|
|
|
|
color_t color1, color2;
|
|
|
|
|
2025-02-23 20:03:34 +01:00
|
|
|
cell *starter;
|
2025-02-23 20:52:23 +01:00
|
|
|
map<cell*, set<int>> same;
|
2020-07-29 23:34:00 +02:00
|
|
|
map<cell*, shiftmatrix> gm;
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
bool is_connected(cellwalker cw) {
|
2025-02-23 20:52:23 +01:00
|
|
|
return same[cw.at].count(cw.spin);
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void be_connected(cellwalker cw) {
|
|
|
|
// transmatrix T = gm[cw.at];
|
2025-02-23 20:52:23 +01:00
|
|
|
same[cw.at].insert(cw.spin);
|
2018-11-07 00:53:10 +01:00
|
|
|
cw += wstep;
|
2025-02-23 20:52:23 +01:00
|
|
|
same[cw.at].insert(cw.spin);
|
2018-11-07 00:53:10 +01:00
|
|
|
/* printf("%s", display(T * C0));
|
|
|
|
printf(" %s\n", display(gm[cw.at] * C0)); */
|
|
|
|
// queueline(T * C0, gm[cw.at] * C0, 0xFF0000FF, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
int funmode = 0;
|
|
|
|
|
2020-07-29 23:34:00 +02:00
|
|
|
shiftpoint corner(cellwalker cw) {
|
|
|
|
shiftmatrix T = gm[cw.at];
|
2025-02-23 21:03:03 +01:00
|
|
|
|
|
|
|
if(funmode == 3) switch(geometry) {
|
|
|
|
case gKleinQuartic: {
|
|
|
|
ld a = edge_of_triangle_with_angles(90._deg, M_PI/14, M_PI*2/14);
|
|
|
|
shiftpoint at = gm[cw.at] * get_corner_position(cw.at, cw.spin+(cw.mirrored?0:1), 3);
|
|
|
|
shiftpoint best = at; ld bestdist = 999;
|
|
|
|
for(int i=0; i<14; i++) {
|
|
|
|
shiftmatrix sm = gm[starter];
|
|
|
|
if(variation == eVariation::untruncated)
|
|
|
|
sm = sm * rgpushxto0(get_corner_position(starter, 0, 3));
|
|
|
|
auto s = sm * xspinpush0(i * M_PI/7, a);
|
|
|
|
ld d = hdist(at, s);
|
|
|
|
if(d < bestdist) bestdist = d, best = s;
|
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
default: /* no special */;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(funmode == 2 && BITRUNCATED) {
|
2018-11-07 00:53:10 +01:00
|
|
|
while(cw.at->type != S7) {
|
|
|
|
cw++;
|
2019-11-23 23:52:04 +01:00
|
|
|
T = T * currentmap->adj(cw.at, cw.spin);
|
2018-11-07 00:53:10 +01:00
|
|
|
cw += wstep;
|
|
|
|
}
|
|
|
|
return T * C0;
|
|
|
|
}
|
|
|
|
return gm[cw.at] * get_corner_position(cw.at, cw.spin+(cw.mirrored?0:1), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
transmatrix rel(cellwalker cw) {
|
2019-11-23 23:52:04 +01:00
|
|
|
return currentmap->adj(cw.at, cw.spin);
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
|
2018-11-08 13:02:44 +01:00
|
|
|
ld label_dist = .3;
|
|
|
|
|
2020-07-29 23:34:00 +02:00
|
|
|
shiftmatrix labelpos(shiftpoint h1, shiftpoint h2) {
|
|
|
|
shiftpoint h = mid(h1, h2);
|
|
|
|
shiftmatrix T = rgpushxto0(h);
|
|
|
|
hyperpoint hx = inverse_shift(T, h2);
|
2018-11-07 00:53:10 +01:00
|
|
|
ld alpha = atan2(-hx[1], hx[0]);
|
2022-11-12 22:38:45 +01:00
|
|
|
return T * xspinpush(alpha + 90._deg, label_dist);
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
|
2018-11-08 13:02:44 +01:00
|
|
|
ld widthfactor = 5;
|
|
|
|
ld label_scale = 1;
|
|
|
|
|
2025-02-23 20:54:23 +01:00
|
|
|
bool single_edges = false;
|
|
|
|
bool fill_faces = true;
|
|
|
|
|
|
|
|
int group_count(cellwalker cw) {
|
|
|
|
if(is_connected(cw)) return 0;
|
|
|
|
auto cw1 = cw;
|
|
|
|
int groups = 0;
|
|
|
|
do {
|
|
|
|
if(!is_connected(cw1)) groups++;
|
|
|
|
cw1 = cw1 + wstep - 1;
|
|
|
|
}
|
|
|
|
while(cw1 != cw);
|
|
|
|
return groups;
|
|
|
|
}
|
|
|
|
|
2018-11-07 00:53:10 +01:00
|
|
|
void fundamental_marker() {
|
2019-11-30 18:52:24 +01:00
|
|
|
if(!funmode || !quotient) return;
|
2018-11-07 00:53:10 +01:00
|
|
|
same.clear();
|
|
|
|
gm.clear();
|
|
|
|
|
2025-02-23 20:03:34 +01:00
|
|
|
gm[starter] = ggmatrix(starter);
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
vector<cell*> cells;
|
2025-02-23 20:03:34 +01:00
|
|
|
cells.push_back(starter);
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
int tree_edges = 0;
|
|
|
|
int face_edges = 0;
|
|
|
|
|
|
|
|
for(int k=0; k<isize(cells); k++) {
|
|
|
|
cell *c = cells[k];
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cellwalker cw(c, i);
|
|
|
|
cell *c2 = cw.cpeek();
|
|
|
|
if(gm.count(c2)) continue;
|
|
|
|
gm[c2] = gm[c] * rel(cw);
|
|
|
|
// queueline(gm[c2] * C0, gm[c2] * xspinpush0(ticks, 0.2), 0xFFFFFFFF, 3);
|
|
|
|
be_connected(cw);
|
|
|
|
tree_edges++;
|
|
|
|
cells.push_back(c2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-23 20:54:23 +01:00
|
|
|
while(fill_faces) {
|
2018-11-07 00:53:10 +01:00
|
|
|
int f = face_edges;
|
|
|
|
for(int k=0; k<isize(cells); k++) {
|
|
|
|
cell *c = cells[k];
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cellwalker cw(c, i);
|
2025-02-23 20:54:23 +01:00
|
|
|
if(group_count(cw) == 1) {
|
2018-11-07 00:53:10 +01:00
|
|
|
face_edges++;
|
2025-02-23 20:54:23 +01:00
|
|
|
be_connected(cw);
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(f == face_edges) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cellwalker cw;
|
|
|
|
|
|
|
|
int corners = 0;
|
|
|
|
|
|
|
|
for(int k=0; k<isize(cells); k++) {
|
|
|
|
cell *c = cells[k];
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cellwalker cw0(c, i);
|
2025-02-23 20:54:23 +01:00
|
|
|
if(single_edges) {
|
|
|
|
if(!is_connected(cw0)) corners++, cw = cw0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(group_count(cw0) >= 3) corners++, cw = cw0;
|
|
|
|
}
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
}
|
2025-02-23 20:54:23 +01:00
|
|
|
|
|
|
|
if(!corners) return;
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
// printf("tree edges = %d, face edges = %d, corners = %d\n", tree_edges, face_edges, corners);
|
2025-02-23 20:03:00 +01:00
|
|
|
|
|
|
|
vector<cellwalker> cornerlist;
|
|
|
|
map<cellwalker, int> corner_id;
|
2025-02-23 20:54:23 +01:00
|
|
|
|
2018-11-07 00:53:10 +01:00
|
|
|
for(int ci=0; ci<corners; ci++) {
|
2025-02-23 20:54:23 +01:00
|
|
|
corner_id[cw] = cornerlist.size();
|
|
|
|
cornerlist.push_back(cw);
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
while(true) {
|
|
|
|
cw++;
|
2025-02-23 20:54:23 +01:00
|
|
|
while(is_connected(cw)) {
|
2018-11-07 00:53:10 +01:00
|
|
|
cw += wstep;
|
|
|
|
cw++;
|
|
|
|
}
|
2025-02-23 20:54:23 +01:00
|
|
|
if(single_edges || group_count(cw) >= 3) break;
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
}
|
2025-02-23 20:03:00 +01:00
|
|
|
auto corners0 = corners;
|
|
|
|
corners = isize(cornerlist);
|
|
|
|
cornerlist.push_back(cw);
|
|
|
|
|
|
|
|
if(corners0 != corners) println(hlog, "corners=", tie(corners0, corners));
|
2018-11-07 00:53:10 +01:00
|
|
|
|
2020-07-29 23:34:00 +02:00
|
|
|
vector<pair<shiftmatrix, shiftmatrix>> nearm;
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
for(int ci=0; ci<corners; ci++) {
|
2025-02-23 20:03:00 +01:00
|
|
|
auto cw = cornerlist[ci];
|
2018-11-07 00:53:10 +01:00
|
|
|
for(int u=0; u<1; u++) {
|
|
|
|
cellwalker cw1 = cw+u+wstep+(u-1);
|
|
|
|
/* printf("%p/%d %p/%d ", cw.at, cw.spin, cw1.at, cw1.spin);
|
|
|
|
printf("[%d %d %d] ", is_connected(cw), is_connected(cw+1), is_connected(cw+wstep-1));
|
|
|
|
printf("[%d %d %d] ", is_connected(cw1), is_connected(cw1+1), is_connected(cw1+wstep-1));
|
|
|
|
printf("%d %d;\n", !!next_corner.count(cw1), !!next_corner.count(cw1+wmirror-1)); */
|
2020-07-29 23:34:00 +02:00
|
|
|
shiftmatrix T_here = gm[cw.at] * rel(cw+u);
|
|
|
|
shiftmatrix T_there = gm[cw1.at];
|
|
|
|
nearm.emplace_back(T_here, T_there);
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 13:02:44 +01:00
|
|
|
vid.linewidth *= widthfactor;
|
2018-11-07 00:53:10 +01:00
|
|
|
|
2025-02-23 20:03:00 +01:00
|
|
|
vector<shiftpoint> cornerpos;
|
|
|
|
for(auto c: cornerlist) cornerpos.push_back(corner(c));
|
|
|
|
|
2018-11-07 00:53:10 +01:00
|
|
|
for(int ci=0; ci<corners; ci++) {
|
|
|
|
|
2025-02-23 20:03:00 +01:00
|
|
|
shiftpoint h = cornerpos[ci];
|
|
|
|
shiftpoint h2 = cornerpos[ci+1];
|
2018-11-07 00:53:10 +01:00
|
|
|
|
2020-07-29 23:34:00 +02:00
|
|
|
for(auto& n: nearm) queueline(n.first * inverse_shift(n.second, h), n.first * inverse_shift(n.second, h2), color1, 3);
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for(int ci=0; ci<corners; ci++) {
|
|
|
|
|
2025-02-23 20:03:00 +01:00
|
|
|
shiftpoint h = cornerpos[ci];
|
|
|
|
shiftpoint h2 = cornerpos[ci+1];
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
queueline(h, h2, color2, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(0) for(int k=0; k<isize(cells); k++) {
|
|
|
|
cell *c = cells[k];
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cellwalker cw0(c, i);
|
|
|
|
if(!is_connected(cw0)) continue;
|
|
|
|
int v = 0;
|
|
|
|
for(auto& n: nearm) {
|
2020-07-29 23:34:00 +02:00
|
|
|
queueline(n.first * inverse_shift(n.second, gm[cw0.at]) * xspinpush0(v, .05), n.first * inverse_shift(n.second, gm[cw0.cpeek()]) * xspinpush0(v, .05), 0xFF8000FF, 0);
|
2018-11-07 00:53:10 +01:00
|
|
|
v++;
|
|
|
|
}
|
|
|
|
queueline(gm[cw0.at] * C0, gm[cw0.cpeek()] * C0, 0xFF0000FF, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set<cellwalker> visited;
|
|
|
|
|
|
|
|
int id = 0;
|
|
|
|
|
|
|
|
for(int ci=0; ci<corners; ci++) {
|
|
|
|
|
2025-02-23 20:03:00 +01:00
|
|
|
auto cw = cornerlist[ci];
|
2018-11-07 00:53:10 +01:00
|
|
|
cellwalker cw1 = (cw+1+wstep);
|
|
|
|
bool mirrored = false;
|
2025-02-23 20:54:23 +01:00
|
|
|
while(is_connected(cw1)) cw1 = cw1 + 1 + wstep;
|
2025-02-23 20:03:00 +01:00
|
|
|
if(!corner_id.count(cw1)) cw1 = cw1 + wmirror - 1, mirrored = true;
|
|
|
|
if(!corner_id.count(cw1)) println(hlog, "still bad");
|
|
|
|
auto ci1 = corner_id[cw1];
|
|
|
|
auto nx = cornerlist[ci+1];
|
|
|
|
auto nx1 = cornerlist[ci1+1];
|
|
|
|
auto pv1 = cornerlist[(ci1+corners-1) % corners];
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
// visited.insert(next_corner[cw]);
|
|
|
|
// cellwalker cw2 = next_corner[cw];
|
2025-02-23 20:03:00 +01:00
|
|
|
if(nx < (mirrored ? nx1 : cw1)) {
|
2018-11-07 00:53:10 +01:00
|
|
|
|
|
|
|
int mc = (mirrored ? color1 : color2) >> 8;
|
2025-02-23 20:03:00 +01:00
|
|
|
if(hdist(corner(cw), corner(nx)) > 1e-3) {
|
|
|
|
queuestr(labelpos(corner(cw), corner(nx)), label_scale/cgi.scalefactor, its(id), mc);
|
2018-11-07 00:53:10 +01:00
|
|
|
if(mirrored)
|
2025-02-23 20:03:00 +01:00
|
|
|
queuestr(labelpos(corner(cw1), corner(nx1)), label_scale/cgi.scalefactor, its(id), mc);
|
2018-11-07 00:53:10 +01:00
|
|
|
else
|
2025-02-23 20:03:00 +01:00
|
|
|
queuestr(labelpos(corner(pv1), corner(cw1)), label_scale/cgi.scalefactor, its(id), mc);
|
2018-11-07 00:53:10 +01:00
|
|
|
id++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-08 13:02:44 +01:00
|
|
|
vid.linewidth /= widthfactor;
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
|
2025-02-23 20:06:52 +01:00
|
|
|
void showMenu() {
|
|
|
|
cmode = sm::SIDE | sm::MAYDARK;
|
|
|
|
gamescreen();
|
|
|
|
dialog::init(XLAT("display fundamental domains"), 0xFFFFFFFF, 150, 0);
|
2025-02-23 21:03:03 +01:00
|
|
|
vector<string> mode_names = {"no display", "corners", "centers", "special"};
|
|
|
|
dialog::addSelItem("mode", mode_names[funmode], 'm');
|
|
|
|
dialog::add_action([] { funmode = (1 + funmode) % 4; });
|
2025-02-23 20:06:52 +01:00
|
|
|
dialog::addSelItem("label distance", fts(label_dist), 'd');
|
|
|
|
dialog::add_action([] {
|
|
|
|
dialog::editNumber(label_dist, 0, 10, .1, 0.5, "label fistance", "label distance");
|
|
|
|
});
|
|
|
|
dialog::addSelItem("label scale", fts(label_scale), 's');
|
|
|
|
dialog::add_action([] {
|
|
|
|
dialog::editNumber(label_scale, 0, 10, .1, 0.5, "label scale", "label scale");
|
|
|
|
});
|
|
|
|
dialog::addSelItem("line width factor", fts(widthfactor), 'w');
|
|
|
|
dialog::add_action([] {
|
|
|
|
dialog::editNumber(widthfactor, 0, 5, .1, 1, "line width factor", "line width factor");
|
|
|
|
});
|
|
|
|
dialog::addColorItem("color of other domains", color1, 'o');
|
|
|
|
dialog::add_action([] () {
|
|
|
|
dialog::openColorDialog(color1, NULL);
|
|
|
|
dialog::get_di().dialogflags |= sm::MAYDARK | sm::SIDE;
|
|
|
|
});
|
|
|
|
dialog::addColorItem("color of primary domain", color2, 'p');
|
|
|
|
dialog::add_action([] () {
|
|
|
|
dialog::openColorDialog(color2, NULL);
|
|
|
|
dialog::get_di().dialogflags |= sm::MAYDARK | sm::SIDE;
|
|
|
|
});
|
2025-02-23 20:54:43 +01:00
|
|
|
dialog::addSelItem("set the central tile to current position", its(celldistance(starter, cwt.at)), 's');
|
|
|
|
dialog::add_action([] () {
|
|
|
|
starter = cwt.at;
|
|
|
|
});
|
2025-02-23 20:06:52 +01:00
|
|
|
|
|
|
|
dialog::addBack();
|
|
|
|
dialog::display();
|
|
|
|
}
|
|
|
|
|
2025-02-23 20:06:18 +01:00
|
|
|
void enable_fundamental() {
|
|
|
|
start_game(); starter = cwt.at;
|
|
|
|
rogueviz::rv_hook(hooks_frame, 100, fundamental_marker);
|
|
|
|
rogueviz::rv_hook(hooks_clearmemory, 100, [] { same.clear(); gm.clear(); });
|
2025-02-23 20:06:52 +01:00
|
|
|
rogueviz::rv_hook(hooks_o_key, 80, [] (o_funcs& v) { v.push_back(named_dialog("fundamental", showMenu)); });
|
2025-02-23 20:06:18 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 00:53:10 +01:00
|
|
|
int readArgs() {
|
|
|
|
using namespace arg;
|
|
|
|
|
|
|
|
if(0) ;
|
2025-02-23 20:55:07 +01:00
|
|
|
else if(argis("-fundamental0")) {
|
|
|
|
enable_fundamental();
|
|
|
|
}
|
2018-11-07 00:53:10 +01:00
|
|
|
else if(argis("-fundamental")) {
|
|
|
|
shift(); funmode = argi();
|
|
|
|
shift(); color1 = arghex();
|
|
|
|
shift(); color2 = arghex();
|
2018-11-09 14:26:31 +01:00
|
|
|
shift_arg_formula(widthfactor);
|
|
|
|
shift_arg_formula(label_scale);
|
|
|
|
shift_arg_formula(label_dist);
|
2025-02-23 20:06:18 +01:00
|
|
|
enable_fundamental();
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|
2025-02-23 20:55:07 +01:00
|
|
|
else if(argis("-fundamental-more")) {
|
|
|
|
shift(); single_edges = argi();
|
|
|
|
shift(); fill_faces = argi();
|
|
|
|
}
|
2018-11-07 00:53:10 +01:00
|
|
|
else return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2025-02-23 20:06:18 +01:00
|
|
|
auto fundamentalhook = addHook(hooks_args, 100, readArgs);
|
|
|
|
}
|
2018-11-07 00:53:10 +01:00
|
|
|
}
|