2019-08-10 11:43:24 +00:00
|
|
|
// Hyperbolic Rogue -- advanced geometry
|
|
|
|
// Copyright (C) 2011-2019 Zeno Rogue, see 'hyper.cpp' for details
|
2018-08-17 14:47:06 +00:00
|
|
|
|
2019-08-10 11:43:24 +00:00
|
|
|
/** \file geometry2.cpp
|
|
|
|
* \brief Matrices to transform between coordinates of various cells, coordinates of cell corners, etc.
|
|
|
|
*/
|
2018-08-17 14:47:06 +00:00
|
|
|
|
2019-09-05 07:15:40 +00:00
|
|
|
#include "hyper.h"
|
2018-08-17 14:47:06 +00:00
|
|
|
namespace hr {
|
|
|
|
|
|
|
|
transmatrix &ggmatrix(cell *c);
|
|
|
|
|
|
|
|
void fixelliptic(transmatrix& at) {
|
2019-08-17 21:28:41 +00:00
|
|
|
if(elliptic && at[LDIM][LDIM] < 0) {
|
2019-02-25 17:13:09 +00:00
|
|
|
for(int i=0; i<MDIM; i++) for(int j=0; j<MDIM; j++)
|
2018-08-17 14:47:06 +00:00
|
|
|
at[i][j] = -at[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fixelliptic(hyperpoint& h) {
|
2019-08-17 21:28:41 +00:00
|
|
|
if(elliptic && h[LDIM] < 0)
|
2019-02-25 17:13:09 +00:00
|
|
|
for(int i=0; i<MDIM; i++) h[i] = -h[i];
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX transmatrix master_relative(cell *c, bool get_inverse IS(false)) {
|
2019-02-17 17:28:20 +00:00
|
|
|
if(0) ;
|
|
|
|
#if CAP_IRR
|
|
|
|
else if(IRREGULAR) {
|
2018-08-17 14:47:06 +00:00
|
|
|
int id = irr::cellindex[c];
|
|
|
|
ld alpha = 2 * M_PI / S7 * irr::periodmap[c->master].base.spin;
|
|
|
|
return get_inverse ? irr::cells[id].rpusher * spin(-alpha-master_to_c7_angle()): spin(alpha + master_to_c7_angle()) * irr::cells[id].pusher;
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_GP
|
2018-08-28 15:17:34 +00:00
|
|
|
else if(GOLDBERG) {
|
2018-08-17 14:47:06 +00:00
|
|
|
if(c == c->master->c7) {
|
|
|
|
return spin((get_inverse?-1:1) * master_to_c7_angle());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
auto li = gp::get_local_info(c);
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix T = spin(master_to_c7_angle()) * cgi.gpdata->Tf[li.last_dir][li.relative.first&31][li.relative.second&31][gp::fixg6(li.total_dir)];
|
2018-08-17 14:47:06 +00:00
|
|
|
if(get_inverse) T = inverse(T);
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-08-28 15:17:34 +00:00
|
|
|
else if(BITRUNCATED && !euclid) {
|
2018-08-17 22:46:45 +00:00
|
|
|
for(int d=0; d<S7; d++) if(c->master->c7->move(d) == c)
|
2019-05-26 16:04:02 +00:00
|
|
|
return (get_inverse?cgi.invhexmove:cgi.hexmove)[d];
|
2018-08-17 14:47:06 +00:00
|
|
|
return Id;
|
|
|
|
}
|
2019-05-08 16:33:08 +00:00
|
|
|
else if(WDIM == 3 || euclid)
|
2019-02-27 16:59:47 +00:00
|
|
|
return Id;
|
2018-08-17 14:47:06 +00:00
|
|
|
else
|
|
|
|
return pispin * Id;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX transmatrix calc_relative_matrix(cell *c2, cell *c1, int direction_hint) {
|
2018-08-19 14:28:36 +00:00
|
|
|
return calc_relative_matrix(c2, c1, ddspin(c1, direction_hint) * xpush0(1e-2));
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX transmatrix calc_relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hint) {
|
2019-03-08 21:38:44 +00:00
|
|
|
return currentmap->relative_matrix(c2, c1, point_hint);
|
|
|
|
}
|
|
|
|
|
2018-08-17 14:47:06 +00:00
|
|
|
// target, source, direction from source to target
|
|
|
|
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_GP
|
2018-08-17 14:47:06 +00:00
|
|
|
namespace gp { extern gp::local_info draw_li; }
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-08-17 14:47:06 +00:00
|
|
|
|
2019-03-08 21:38:44 +00:00
|
|
|
transmatrix hrmap_standard::relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hint) {
|
2018-08-17 14:47:06 +00:00
|
|
|
|
|
|
|
heptagon *h1 = c1->master;
|
|
|
|
transmatrix gm = master_relative(c1, true);
|
|
|
|
heptagon *h2 = c2->master;
|
|
|
|
transmatrix where = master_relative(c2);
|
|
|
|
|
|
|
|
// always add to last!
|
|
|
|
//bool hsol = false;
|
|
|
|
//transmatrix sol;
|
|
|
|
|
2018-12-04 20:17:16 +00:00
|
|
|
set<heptagon*> visited;
|
|
|
|
map<ld, vector<pair<heptagon*, transmatrix>>> hbdist;
|
|
|
|
|
2018-12-01 22:53:03 +00:00
|
|
|
int steps = 0;
|
2018-08-17 14:47:06 +00:00
|
|
|
while(h1 != h2) {
|
2018-12-04 20:17:16 +00:00
|
|
|
steps++; if(steps > 10000) {
|
|
|
|
println(hlog, "not found"); return Id;
|
|
|
|
}
|
2018-12-13 16:02:38 +00:00
|
|
|
if(bounded) {
|
2018-08-17 14:47:06 +00:00
|
|
|
transmatrix T;
|
|
|
|
ld bestdist = 1e9;
|
2018-08-17 22:46:45 +00:00
|
|
|
for(int d=0; d<S7; d++) if(h2->move(d)) {
|
|
|
|
int sp = h2->c.spin(d);
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix S = cgi.heptmove[sp] * spin(2*M_PI*d/S7);
|
|
|
|
if(h2->c.mirror(d)) S = cgi.heptmove[sp] * Mirror * spin(2*M_PI*d/S7);
|
2018-08-17 22:46:45 +00:00
|
|
|
if(h2->move(d) == h1) {
|
2018-08-17 14:47:06 +00:00
|
|
|
transmatrix T1 = gm * S * where;
|
|
|
|
auto curdist = hdist(tC0(T1), point_hint);
|
|
|
|
if(curdist < bestdist) T = T1, bestdist = curdist;
|
|
|
|
}
|
2018-09-23 14:30:56 +00:00
|
|
|
if(geometry != gMinimal) for(int e=0; e<S7; e++) if(h2->move(d)->move(e) == h1) {
|
2018-08-17 22:46:45 +00:00
|
|
|
int sp2 = h2->move(d)->c.spin(e);
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix T1 = gm * cgi.heptmove[sp2] * spin(2*M_PI*e/S7) * S * where;
|
2018-08-17 14:47:06 +00:00
|
|
|
auto curdist = hdist(tC0(T1), point_hint);
|
|
|
|
if(curdist < bestdist) T = T1, bestdist = curdist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(bestdist < 1e8) return T;
|
|
|
|
}
|
2018-08-17 22:46:45 +00:00
|
|
|
for(int d=0; d<S7; d++) if(h2->move(d) == h1) {
|
|
|
|
int sp = h2->c.spin(d);
|
2019-05-26 16:04:02 +00:00
|
|
|
return gm * cgi.heptmove[sp] * spin(2*M_PI*d/S7) * where;
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
2018-12-04 20:17:16 +00:00
|
|
|
if(among(geometry, gFieldQuotient, gBring, gMacbeath)) {
|
|
|
|
int bestdist = 1000000, bestd = 0;
|
2018-08-17 14:47:06 +00:00
|
|
|
for(int d=0; d<S7; d++) {
|
2018-12-13 16:02:38 +00:00
|
|
|
int dist = celldistance(h2->cmove(d)->c7, c1);
|
2018-08-17 14:47:06 +00:00
|
|
|
if(dist < bestdist) bestdist = dist, bestd = d;
|
|
|
|
}
|
2018-08-17 22:46:45 +00:00
|
|
|
int sp = h2->c.spin(bestd);
|
2019-05-26 16:04:02 +00:00
|
|
|
where = cgi.heptmove[sp] * spin(2*M_PI*bestd/S7) * where;
|
2018-08-17 22:46:45 +00:00
|
|
|
h2 = h2->move(bestd);
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_CRYSTAL
|
2019-08-22 10:14:39 +00:00
|
|
|
else if(cryst) {
|
2018-12-04 20:17:16 +00:00
|
|
|
for(int d3=0; d3<S7; d3++) {
|
|
|
|
auto h3 = h2->cmove(d3);
|
|
|
|
if(visited.count(h3)) continue;
|
|
|
|
visited.insert(h3);
|
|
|
|
int sp3 = h2->c.spin(d3);
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix where3 = cgi.heptmove[sp3] * spin(2*M_PI*d3/S7) * where;
|
2018-12-04 20:17:16 +00:00
|
|
|
ld dist = crystal::space_distance(h3->c7, c1);
|
|
|
|
hbdist[dist].emplace_back(h3, where3);
|
|
|
|
}
|
|
|
|
auto &bestv = hbdist.begin()->second;
|
|
|
|
tie(h2, where) = bestv.back();
|
|
|
|
bestv.pop_back();
|
|
|
|
if(bestv.empty()) hbdist.erase(hbdist.begin());
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-08-17 14:47:06 +00:00
|
|
|
else if(h1->distance < h2->distance) {
|
2018-08-17 22:46:45 +00:00
|
|
|
int sp = h2->c.spin(0);
|
|
|
|
h2 = h2->move(0);
|
2019-05-26 16:04:02 +00:00
|
|
|
where = cgi.heptmove[sp] * where;
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-08-17 22:46:45 +00:00
|
|
|
int sp = h1->c.spin(0);
|
|
|
|
h1 = h1->move(0);
|
2019-05-26 16:04:02 +00:00
|
|
|
gm = gm * cgi.invheptmove[sp];
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return gm * where;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX transmatrix &ggmatrix(cell *c) {
|
2018-08-17 14:47:06 +00:00
|
|
|
transmatrix& t = gmatrix[c];
|
2019-08-17 21:28:41 +00:00
|
|
|
if(t[LDIM][LDIM] == 0) {
|
2019-07-25 10:16:25 +00:00
|
|
|
if(euwrap && centerover.at && masterless)
|
2018-08-17 22:46:45 +00:00
|
|
|
t = calc_relative_matrix(c, centerover.at, C0);
|
2019-07-25 10:16:25 +00:00
|
|
|
else if(masterless && WDIM == 2) {
|
2018-08-17 22:46:45 +00:00
|
|
|
if(!centerover.at) centerover = cwt;
|
2018-08-17 14:47:06 +00:00
|
|
|
t = View * eumove(cell_to_vec(c) - cellwalker_to_vec(centerover));
|
|
|
|
}
|
|
|
|
else
|
2019-08-17 21:29:11 +00:00
|
|
|
t = actualV(viewctr, actual_view_transform * View) * calc_relative_matrix(c, viewcenter(), C0);
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX transmatrix calc_relative_matrix_help(cell *c, heptagon *h1) {
|
2018-08-17 14:47:06 +00:00
|
|
|
transmatrix gm = Id;
|
|
|
|
heptagon *h2 = c->master;
|
|
|
|
transmatrix where = Id;
|
2019-02-17 17:28:20 +00:00
|
|
|
if(0);
|
|
|
|
#if CAP_GP
|
|
|
|
else if(GOLDBERG && c != c->master->c7) {
|
2018-08-17 14:47:06 +00:00
|
|
|
auto li = gp::get_local_info(c);
|
2019-08-09 12:12:33 +00:00
|
|
|
where = cgi.gpdata->Tf[li.last_dir][li.relative.first&31][li.relative.second&31][gmod(li.total_dir, S6)];
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-08-28 15:17:34 +00:00
|
|
|
else if(BITRUNCATED) for(int d=0; d<S7; d++) if(h2->c7->move(d) == c)
|
2019-05-26 16:04:02 +00:00
|
|
|
where = cgi.hexmove[d];
|
2018-08-17 14:47:06 +00:00
|
|
|
// always add to last!
|
|
|
|
while(h1 != h2) {
|
2018-08-17 22:46:45 +00:00
|
|
|
for(int d=0; d<S7; d++) if(h1->move(d) == h2) printf("(adj) ");
|
2018-08-17 14:47:06 +00:00
|
|
|
if(h1->distance < h2->distance) {
|
2018-08-17 22:46:45 +00:00
|
|
|
int sp = h2->c.spin(0);
|
2018-08-17 14:47:06 +00:00
|
|
|
printf("A%d ", sp);
|
2018-08-17 22:46:45 +00:00
|
|
|
h2 = h2->move(0);
|
2019-05-26 16:04:02 +00:00
|
|
|
where = cgi.heptmove[sp] * where;
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-08-17 22:46:45 +00:00
|
|
|
int sp = h1->c.spin(0);
|
2018-08-17 14:47:06 +00:00
|
|
|
printf("B%d ", sp);
|
2018-08-17 22:46:45 +00:00
|
|
|
h1 = h1->move(0);
|
2019-05-26 16:04:02 +00:00
|
|
|
gm = gm * cgi.invheptmove[sp];
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-24 16:01:49 +00:00
|
|
|
println(hlog, "OK");
|
|
|
|
println(hlog, gm * where);
|
2018-08-17 14:47:06 +00:00
|
|
|
return gm * where;
|
|
|
|
}
|
|
|
|
|
2019-04-30 01:35:23 +00:00
|
|
|
struct horo_distance {
|
|
|
|
ld a, b;
|
2019-07-31 13:16:13 +00:00
|
|
|
|
|
|
|
void become(hyperpoint h1) {
|
|
|
|
if(sol) {
|
|
|
|
a = abs(h1[2]);
|
|
|
|
b = hypot_d(2, h1);
|
|
|
|
}
|
2019-05-06 23:08:49 +00:00
|
|
|
#if CAP_BT
|
2019-07-31 13:16:13 +00:00
|
|
|
else if(binarytiling) {
|
2019-04-30 01:35:23 +00:00
|
|
|
b = intval(h1, C0);
|
|
|
|
a = abs(binary::horo_level(h1));
|
|
|
|
}
|
2019-05-06 23:08:49 +00:00
|
|
|
#endif
|
2019-08-24 18:29:10 +00:00
|
|
|
else if(hybri)
|
|
|
|
a = 0, b = hdist(h1, C0);
|
|
|
|
else
|
2019-04-30 01:35:23 +00:00
|
|
|
a = 0, b = intval(h1, C0);
|
|
|
|
}
|
2019-07-31 13:16:13 +00:00
|
|
|
|
|
|
|
horo_distance(hyperpoint h) { become(h); }
|
|
|
|
|
2019-04-30 01:35:23 +00:00
|
|
|
horo_distance(hyperpoint h1, const transmatrix& T) {
|
2019-05-06 23:08:49 +00:00
|
|
|
#if CAP_BT
|
2019-07-31 13:16:13 +00:00
|
|
|
if(binarytiling) become(inverse(T) * h1);
|
2019-04-30 01:35:23 +00:00
|
|
|
else
|
2019-05-06 23:08:49 +00:00
|
|
|
#endif
|
2019-08-24 18:29:10 +00:00
|
|
|
if(sol || hybri) become(inverse(T) * h1);
|
|
|
|
else
|
2019-04-30 01:35:23 +00:00
|
|
|
a = 0, b = intval(h1, tC0(T));
|
|
|
|
}
|
|
|
|
bool operator < (const horo_distance z) {
|
2019-05-06 23:08:49 +00:00
|
|
|
#if CAP_BT
|
2019-07-31 13:16:13 +00:00
|
|
|
if(binarytiling || sol) {
|
2019-04-30 01:35:23 +00:00
|
|
|
if(a < z.a-1e-6) return true;
|
|
|
|
if(a > z.a+1e-6) return false;
|
|
|
|
}
|
2019-05-06 23:08:49 +00:00
|
|
|
#endif
|
2019-04-30 01:35:23 +00:00
|
|
|
return b < z.b - 1e-4;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-24 18:29:32 +00:00
|
|
|
template<class T, class U>
|
|
|
|
void virtualRebase_cell(cell*& base, T& at, const U& check) {
|
|
|
|
horo_distance currz(check(at));
|
|
|
|
T best_at = at;
|
|
|
|
while(true) {
|
|
|
|
cell *newbase = NULL;
|
|
|
|
forCellCM(c2, base) {
|
|
|
|
transmatrix V2 = calc_relative_matrix(base, c2, C0);
|
|
|
|
T cand_at = V2 * at;
|
|
|
|
horo_distance newz(check(cand_at));
|
|
|
|
if(newz < currz) {
|
|
|
|
currz = newz;
|
|
|
|
best_at = cand_at;
|
|
|
|
newbase = c2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!newbase) break;
|
|
|
|
base = newbase;
|
|
|
|
at = best_at;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-17 14:47:06 +00:00
|
|
|
template<class T, class U>
|
|
|
|
void virtualRebase(cell*& base, T& at, bool tohex, const U& check) {
|
2019-08-20 14:08:15 +00:00
|
|
|
if(prod) {
|
2019-08-24 12:07:46 +00:00
|
|
|
auto w = hybrid::get_where(base);
|
2019-08-20 14:08:15 +00:00
|
|
|
auto d = product_decompose(check(at)).first;
|
|
|
|
at = mscale(at, -d);
|
2019-08-24 12:07:46 +00:00
|
|
|
hybrid::in_underlying_map([&] { virtualRebase(w.first, at, tohex, check); });
|
2019-08-20 14:08:15 +00:00
|
|
|
if(d > cgi.plevel / 2) { w.second++; d -= cgi.plevel; }
|
|
|
|
if(d < -cgi.plevel / 2) { w.second--; d += cgi.plevel; }
|
|
|
|
at = mscale(at, +d);
|
2019-08-24 12:07:46 +00:00
|
|
|
base = hybrid::get_at(w.first, w.second);
|
2019-08-20 14:08:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-08-24 18:29:32 +00:00
|
|
|
if(sl2) {
|
|
|
|
virtualRebase_cell(base, at, check);
|
|
|
|
return;
|
|
|
|
}
|
2019-05-08 16:33:08 +00:00
|
|
|
if((euclid || sphere) && WDIM == 2) {
|
2018-08-17 14:47:06 +00:00
|
|
|
again:
|
2018-11-27 01:32:11 +00:00
|
|
|
if(euwrap) for(int i=0; i<6; i++) {
|
2018-11-27 15:17:20 +00:00
|
|
|
// fix cylinder and square grid
|
2018-08-17 14:47:06 +00:00
|
|
|
auto newat = eumovedir(3+i) * at;
|
|
|
|
if(hdist0(check(newat)) < hdist0(check(at))) {
|
|
|
|
at = newat;
|
|
|
|
base = createMov(base, i);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else forCellCM(c2, base) {
|
|
|
|
auto newat = inverse(ggmatrix(c2)) * ggmatrix(base) * at;
|
|
|
|
if(hypot(check(newat)[0], check(newat)[1])
|
|
|
|
< hypot(check(at)[0], check(at)[1])) {
|
|
|
|
at = newat;
|
|
|
|
base = c2;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fixelliptic(at);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
at = master_relative(base) * at;
|
|
|
|
base = base->master->c7;
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
|
2019-04-30 01:35:23 +00:00
|
|
|
horo_distance currz(check(at));
|
|
|
|
|
2018-08-17 14:47:06 +00:00
|
|
|
heptagon *h = base->master;
|
|
|
|
|
|
|
|
cell *newbase = NULL;
|
|
|
|
|
|
|
|
transmatrix bestV;
|
|
|
|
|
2019-07-25 10:24:02 +00:00
|
|
|
if(WDIM == 2 && !binarytiling && !penrose) for(int d=0; d<S7; d++) {
|
2018-08-17 22:46:45 +00:00
|
|
|
heptspin hs(h, d, false);
|
2018-08-17 14:47:06 +00:00
|
|
|
heptspin hs2 = hs + wstep;
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix V2 = spin(-hs2.spin*2*M_PI/S7) * cgi.invheptmove[d];
|
2019-04-30 01:35:23 +00:00
|
|
|
horo_distance newz(check(V2 * at));
|
2018-08-17 14:47:06 +00:00
|
|
|
if(newz < currz) {
|
|
|
|
currz = newz;
|
|
|
|
bestV = V2;
|
2018-08-17 22:46:45 +00:00
|
|
|
newbase = hs2.at->c7;
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newbase) {
|
|
|
|
base = newbase;
|
|
|
|
at = bestV * at;
|
|
|
|
}
|
|
|
|
else {
|
2018-08-28 15:17:34 +00:00
|
|
|
if(tohex && BITRUNCATED) for(int d=0; d<S7; d++) {
|
2018-08-17 14:47:06 +00:00
|
|
|
cell *c = createMov(base, d);
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix V2 = spin(-base->c.spin(d)*2*M_PI/S6) * cgi.invhexmove[d];
|
2019-04-30 01:35:23 +00:00
|
|
|
horo_distance newz(check(V2 * at));
|
2018-08-17 14:47:06 +00:00
|
|
|
if(newz < currz) {
|
|
|
|
currz = newz;
|
|
|
|
bestV = V2;
|
|
|
|
newbase = c;
|
|
|
|
}
|
|
|
|
}
|
2018-09-27 23:49:17 +00:00
|
|
|
if(newbase) {
|
|
|
|
base = newbase;
|
|
|
|
at = bestV * at;
|
|
|
|
}
|
|
|
|
else at = master_relative(base, true) * at;
|
2019-08-24 18:29:32 +00:00
|
|
|
if(binarytiling || (tohex && (GOLDBERG || IRREGULAR)) || WDIM == 3 || penrose)
|
|
|
|
virtualRebase_cell(base, at, check);
|
2018-08-17 14:47:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void virtualRebase(cell*& base, transmatrix& at, bool tohex) {
|
2018-08-17 14:47:06 +00:00
|
|
|
virtualRebase(base, at, tohex, tC0);
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void virtualRebase(cell*& base, hyperpoint& h, bool tohex) {
|
2018-09-30 14:23:20 +00:00
|
|
|
// we perform fixing in check, so that it works with larger range
|
2019-02-22 19:58:40 +00:00
|
|
|
virtualRebase(base, h, tohex, [] (const hyperpoint& h) {
|
2019-05-08 16:33:08 +00:00
|
|
|
if(hyperbolic && GDIM == 2) return hpxy(h[0], h[1]);
|
|
|
|
if(hyperbolic && GDIM == 3) return hpxy3(h[0], h[1], h[2]);
|
2019-02-22 19:58:40 +00:00
|
|
|
return h;
|
|
|
|
});
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-18 22:25:43 +00:00
|
|
|
// works only in geometries similar to the standard one, and only on heptagons
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void virtualRebaseSimple(heptagon*& base, transmatrix& at) {
|
2018-08-18 22:25:43 +00:00
|
|
|
|
|
|
|
while(true) {
|
|
|
|
|
2019-08-17 21:28:41 +00:00
|
|
|
double currz = at[LDIM][LDIM];
|
2018-08-18 22:25:43 +00:00
|
|
|
|
|
|
|
heptagon *h = base;
|
|
|
|
|
|
|
|
heptagon *newbase = NULL;
|
|
|
|
|
2019-02-10 19:36:09 +00:00
|
|
|
transmatrix bestV {};
|
2018-08-18 22:25:43 +00:00
|
|
|
|
|
|
|
for(int d=0; d<S7; d++) {
|
|
|
|
heptspin hs(h, d, false);
|
|
|
|
heptspin hs2 = hs + wstep;
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix V2 = spin(-hs2.spin*2*M_PI/S7) * cgi.invheptmove[d] * at;
|
2019-08-17 21:28:41 +00:00
|
|
|
double newz = V2[LDIM][LDIM];
|
2018-08-18 22:25:43 +00:00
|
|
|
if(newz < currz) {
|
|
|
|
currz = newz;
|
|
|
|
bestV = V2;
|
|
|
|
newbase = hs2.at;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newbase) {
|
|
|
|
base = newbase;
|
|
|
|
at = bestV;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX double cellgfxdist(cell *c, int i) {
|
2019-07-25 10:25:11 +00:00
|
|
|
if(euclid && !penrose && !archimedean) {
|
2019-05-26 16:04:02 +00:00
|
|
|
if(c->type == 8 && (i&1)) return cgi.crossf * sqrt(2);
|
|
|
|
return cgi.crossf;
|
2018-11-27 15:15:08 +00:00
|
|
|
}
|
2019-07-25 10:24:02 +00:00
|
|
|
if(NONSTDVAR || archimedean || WDIM == 3 || binarytiling || penrose) return hdist0(tC0(calc_relative_matrix(c->move(i), c, i)));
|
2019-05-26 16:04:02 +00:00
|
|
|
return !BITRUNCATED ? cgi.tessf : (c->type == 6 && (i&1)) ? cgi.hexhexdist : cgi.crossf;
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX transmatrix cellrelmatrix(cell *c, int i) {
|
2019-07-25 10:24:02 +00:00
|
|
|
if(NONSTDVAR || archimedean || penrose) return calc_relative_matrix(c->move(i), c, i);
|
2018-08-17 14:47:06 +00:00
|
|
|
double d = cellgfxdist(c, i);
|
2018-11-27 15:15:08 +00:00
|
|
|
transmatrix T = ddspin(c, i) * xpush(d);
|
|
|
|
if(c->c.mirror(i)) T = T * Mirror;
|
2019-08-26 11:43:18 +00:00
|
|
|
cell *c1 = c->cmove(i);
|
|
|
|
T = T * iddspin(c1, c->c.spin(i), M_PI);
|
2018-11-27 15:15:08 +00:00
|
|
|
return T;
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX double randd() { return (rand() + .5) / (RAND_MAX + 1.); }
|
2018-08-17 14:47:06 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX hyperpoint randomPointIn(int t) {
|
2019-07-25 10:24:02 +00:00
|
|
|
if(NONSTDVAR || archimedean || penrose) {
|
2018-08-20 14:36:45 +00:00
|
|
|
// Let these geometries be less confusing.
|
|
|
|
// Also easier to implement ;)
|
|
|
|
return xspinpush0(2 * M_PI * randd(), asinh(randd() / 20));
|
|
|
|
}
|
2018-08-17 14:47:06 +00:00
|
|
|
while(true) {
|
2018-08-19 14:28:36 +00:00
|
|
|
hyperpoint h = xspinpush0(2*M_PI*(randd()-.5)/t, asinh(randd()));
|
2018-08-17 14:47:06 +00:00
|
|
|
double d =
|
2019-05-26 16:04:02 +00:00
|
|
|
PURE ? cgi.tessf : t == 6 ? cgi.hexhexdist : cgi.crossf;
|
2018-08-17 14:47:06 +00:00
|
|
|
if(hdist0(h) < hdist0(xpush(-d) * h))
|
|
|
|
return spin(2*M_PI/t * (rand() % t)) * h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX hyperpoint get_corner_position(cell *c, int cid, ld cf IS(3)) {
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_GP
|
2018-08-28 15:17:34 +00:00
|
|
|
if(GOLDBERG) return gp::get_corner_position(c, cid, cf);
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_IRR
|
2018-08-28 15:17:34 +00:00
|
|
|
if(IRREGULAR) {
|
2018-08-17 14:47:06 +00:00
|
|
|
auto& vs = irr::cells[irr::cellindex[c]];
|
|
|
|
return mid_at_actual(vs.vertices[cid], 3/cf);
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_BT
|
2019-07-25 10:24:02 +00:00
|
|
|
if(penrose) return kite::get_corner(c, cid, cf);
|
2018-08-17 14:47:06 +00:00
|
|
|
if(binarytiling) {
|
2019-05-08 16:33:08 +00:00
|
|
|
if(WDIM == 3) {
|
2019-02-24 18:40:01 +00:00
|
|
|
println(hlog, "get_corner_position called");
|
|
|
|
return C0;
|
|
|
|
}
|
2019-05-09 15:00:05 +00:00
|
|
|
return mid_at_actual(binary::get_horopoint(binary::get_corner_horo_coordinates(c, cid)), 3/cf);
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_ARCM
|
2018-08-19 21:06:32 +00:00
|
|
|
if(archimedean) {
|
2018-08-20 00:02:45 +00:00
|
|
|
auto &ac = arcm::current;
|
2018-08-29 02:28:34 +00:00
|
|
|
if(PURE) {
|
|
|
|
if(arcm::id_of(c->master) >= ac.N*2) return C0;
|
|
|
|
auto& t = ac.get_triangle(c->master, cid-1);
|
|
|
|
return xspinpush0(-t.first, t.second * 3 / cf * (ac.real_faces == 0 ? 0.999 : 1));
|
|
|
|
}
|
|
|
|
if(BITRUNCATED) {
|
|
|
|
auto& t0 = ac.get_triangle(c->master, cid-1);
|
|
|
|
auto& t1 = ac.get_triangle(c->master, cid);
|
|
|
|
hyperpoint h0 = xspinpush0(-t0.first, t0.second * 3 / cf * (ac.real_faces == 0 ? 0.999 : 1));
|
|
|
|
hyperpoint h1 = xspinpush0(-t1.first, t1.second * 3 / cf * (ac.real_faces == 0 ? 0.999 : 1));
|
|
|
|
return mid3(C0, h0, h1);
|
|
|
|
}
|
2018-08-30 00:11:43 +00:00
|
|
|
if(DUAL) {
|
|
|
|
auto& t0 = ac.get_triangle(c->master, 2*cid-1);
|
|
|
|
return xspinpush0(-t0.first, t0.second * 3 / cf * (ac.real_faces == 0 ? 0.999 : 1));
|
|
|
|
}
|
2018-08-17 19:42:42 +00:00
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-08-28 15:17:34 +00:00
|
|
|
if(PURE) {
|
2019-05-26 16:04:02 +00:00
|
|
|
return ddspin(c,cid,M_PI/S7) * xpush0(cgi.hcrossf * 3 / cf);
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
2018-08-28 15:17:34 +00:00
|
|
|
if(BITRUNCATED) {
|
2018-08-17 14:47:06 +00:00
|
|
|
if(!ishept(c))
|
2019-05-26 16:04:02 +00:00
|
|
|
return ddspin(c,cid,M_PI/S6) * xpush0(cgi.hexvdist * 3 / cf);
|
2018-08-17 14:47:06 +00:00
|
|
|
else
|
2019-05-26 16:04:02 +00:00
|
|
|
return ddspin(c,cid,M_PI/S7) * xpush0(cgi.rhexf * 3 / cf);
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
return C0;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool approx_nearcorner = false;
|
2019-07-25 10:24:02 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX hyperpoint nearcorner(cell *c, int i) {
|
2018-08-28 15:17:34 +00:00
|
|
|
if(GOLDBERG) {
|
2018-08-17 14:47:06 +00:00
|
|
|
cellwalker cw(c, i);
|
|
|
|
cw += wstep;
|
2018-08-17 22:46:45 +00:00
|
|
|
transmatrix cwm = calc_relative_matrix(cw.at, c, i);
|
2018-08-17 14:47:06 +00:00
|
|
|
if(elliptic && cwm[2][2] < 0) cwm = centralsym * cwm;
|
|
|
|
return cwm * C0;
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_IRR
|
2018-08-28 15:17:34 +00:00
|
|
|
if(IRREGULAR) {
|
2018-08-17 14:47:06 +00:00
|
|
|
auto& vs = irr::cells[irr::cellindex[c]];
|
|
|
|
hyperpoint nc = vs.jpoints[vs.neid[i]];
|
|
|
|
return mid_at(C0, nc, .94);
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_ARCM
|
2018-08-19 21:06:32 +00:00
|
|
|
if(archimedean) {
|
2018-08-29 02:28:34 +00:00
|
|
|
if(PURE) {
|
|
|
|
auto &ac = arcm::current;
|
|
|
|
auto& t = ac.get_triangle(c->master, i-1);
|
|
|
|
int id = arcm::id_of(c->master);
|
|
|
|
int id1 = ac.get_adj(ac.get_adj(c->master, i-1), -2).first;
|
|
|
|
return xspinpush0(-t.first - M_PI / c->type, ac.inradius[id/2] + ac.inradius[id1/2] + (ac.real_faces == 0 ? 2 * M_PI / (ac.N == 2 ? 2.1 : ac.N) : 0));
|
|
|
|
}
|
|
|
|
if(BITRUNCATED) {
|
|
|
|
auto &ac = arcm::current;
|
|
|
|
auto& t = ac.get_triangle(c->master, i);
|
|
|
|
return xspinpush0(-t.first, t.second);
|
|
|
|
}
|
2018-08-30 00:11:43 +00:00
|
|
|
if(DUAL) {
|
|
|
|
auto &ac = arcm::current;
|
|
|
|
auto& t = ac.get_triangle(c->master, i * 2);
|
|
|
|
return xspinpush0(-t.first, t.second);
|
|
|
|
}
|
2018-08-17 19:42:42 +00:00
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_BT
|
2019-07-22 09:21:27 +00:00
|
|
|
if(geometry == gBinary4) {
|
|
|
|
ld yx = log(2) / 2;
|
|
|
|
ld yy = yx;
|
|
|
|
hyperpoint neis[5];
|
|
|
|
neis[0] = binary::get_horopoint(2*yy, -0.5);
|
|
|
|
neis[1] = binary::get_horopoint(2*yy, +0.5);
|
|
|
|
neis[2] = binary::get_horopoint(0, 1);
|
|
|
|
neis[3] = binary::get_horopoint(-2*yy, c->master->zebraval ? -0.25 : +0.25);
|
|
|
|
neis[4] = binary::get_horopoint(0, -1);
|
|
|
|
return neis[i];
|
|
|
|
}
|
2019-07-25 10:24:02 +00:00
|
|
|
if(penrose) {
|
|
|
|
if(approx_nearcorner)
|
|
|
|
return kite::get_corner(c, i, 3) + kite::get_corner(c, i+1, 3) - C0;
|
|
|
|
else
|
2019-07-28 10:05:22 +00:00
|
|
|
return calc_relative_matrix(c->cmove(i), c, C0) * C0;
|
2019-07-25 10:24:02 +00:00
|
|
|
}
|
2018-08-17 14:47:06 +00:00
|
|
|
if(binarytiling) {
|
2019-05-08 16:33:08 +00:00
|
|
|
if(WDIM == 3) {
|
2019-02-24 18:40:01 +00:00
|
|
|
println(hlog, "nearcorner called");
|
|
|
|
return Hypc;
|
|
|
|
}
|
2018-08-17 14:47:06 +00:00
|
|
|
ld yx = log(2) / 2;
|
|
|
|
ld yy = yx;
|
|
|
|
// ld xx = 1 / sqrt(2)/2;
|
|
|
|
hyperpoint neis[7];
|
2019-05-09 15:00:05 +00:00
|
|
|
neis[0] = binary::get_horopoint(0, 1);
|
|
|
|
neis[1] = binary::get_horopoint(yy*2, 1);
|
|
|
|
neis[2] = binary::get_horopoint(yy*2, 0);
|
|
|
|
neis[3] = binary::get_horopoint(yy*2, -1);
|
|
|
|
neis[4] = binary::get_horopoint(0, -1);
|
2018-08-17 14:47:06 +00:00
|
|
|
if(c->type == 7)
|
2019-05-09 15:00:05 +00:00
|
|
|
neis[5] = binary::get_horopoint(-yy*2, -.5),
|
|
|
|
neis[6] = binary::get_horopoint(-yy*2, +.5);
|
2018-08-17 14:47:06 +00:00
|
|
|
else
|
2019-05-09 15:00:05 +00:00
|
|
|
neis[5] = binary::get_horopoint(-yy*2, 0);
|
2018-08-17 14:47:06 +00:00
|
|
|
return neis[i];
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-08-19 11:46:05 +00:00
|
|
|
double d = cellgfxdist(c, i);
|
2018-08-19 14:28:36 +00:00
|
|
|
return ddspin(c, i) * xpush0(d);
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX hyperpoint farcorner(cell *c, int i, int which) {
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_GP
|
2018-08-28 15:17:34 +00:00
|
|
|
if(GOLDBERG) {
|
2018-08-17 14:47:06 +00:00
|
|
|
cellwalker cw(c, i);
|
|
|
|
int hint = cw.spin;
|
|
|
|
cw += wstep;
|
2018-08-17 22:46:45 +00:00
|
|
|
transmatrix cwm = calc_relative_matrix(cw.at, c, hint);
|
2018-08-20 15:26:29 +00:00
|
|
|
if(elliptic && cwm[2][2] < 0) cwm = centralsym * cwm;
|
2018-08-17 14:47:06 +00:00
|
|
|
// hyperpoint nfar = cwm*C0;
|
2018-08-17 22:46:45 +00:00
|
|
|
auto li1 = gp::get_local_info(cw.at);
|
2018-08-17 14:47:06 +00:00
|
|
|
if(which == 0)
|
|
|
|
return cwm * get_corner_position(li1, (cw+2).spin);
|
|
|
|
if(which == 1)
|
|
|
|
return cwm * get_corner_position(li1, (cw-1).spin);
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_IRR
|
2018-08-28 15:17:34 +00:00
|
|
|
if(IRREGULAR) {
|
2018-08-17 14:47:06 +00:00
|
|
|
auto& vs = irr::cells[irr::cellindex[c]];
|
|
|
|
int neid = vs.neid[i];
|
|
|
|
int spin = vs.spin[i];
|
|
|
|
auto &vs2 = irr::cells[neid];
|
|
|
|
int cor2 = isize(vs2.vertices);
|
|
|
|
transmatrix rel = vs.rpusher * vs.relmatrices[vs2.owner] * vs2.pusher;
|
|
|
|
|
|
|
|
if(which == 0) return rel * vs2.vertices[(spin+2)%cor2];
|
|
|
|
if(which == 1) return rel * vs2.vertices[(spin+cor2-1)%cor2];
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_BT
|
2019-07-25 10:24:02 +00:00
|
|
|
if(binarytiling || penrose)
|
2018-08-17 14:47:06 +00:00
|
|
|
return nearcorner(c, (i+which) % c->type); // lazy
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_ARCM
|
2018-08-19 21:06:32 +00:00
|
|
|
if(archimedean) {
|
2018-08-29 02:28:34 +00:00
|
|
|
if(PURE) {
|
|
|
|
auto &ac = arcm::current;
|
|
|
|
auto& t = ac.get_triangle(c->master, i-1);
|
|
|
|
int id = arcm::id_of(c->master);
|
|
|
|
auto id1 = ac.get_adj(ac.get_adj(c->master, i-1), -2).first;
|
|
|
|
int n1 = isize(ac.adjacent[id1]);
|
|
|
|
return spin(-t.first - M_PI / c->type) * xpush(ac.inradius[id/2] + ac.inradius[id1/2]) * xspinpush0(M_PI + M_PI/n1*(which?3:-3), ac.circumradius[id1/2]);
|
|
|
|
}
|
2018-08-30 00:11:43 +00:00
|
|
|
if(BITRUNCATED || DUAL) {
|
2018-08-30 14:04:28 +00:00
|
|
|
int mul = DUALMUL;
|
2018-08-29 02:28:34 +00:00
|
|
|
auto &ac = arcm::current;
|
2018-08-30 00:11:43 +00:00
|
|
|
auto adj = ac.get_adj(c->master, i * mul);
|
2018-08-29 02:28:34 +00:00
|
|
|
heptagon h; cell cx; cx.master = &h;
|
|
|
|
arcm::id_of(&h) = adj.first;
|
|
|
|
arcm::parent_index_of(&h) = adj.second;
|
|
|
|
|
|
|
|
auto& t1 = arcm::current.get_triangle(c->master, i);
|
|
|
|
|
|
|
|
auto& t2 = arcm::current.get_triangle(adj);
|
|
|
|
|
2018-08-30 00:11:43 +00:00
|
|
|
return spin(-t1.first) * xpush(t1.second) * spin(M_PI + t2.first) * get_corner_position(&cx, which ? -mul : 2*mul);
|
2018-08-29 02:28:34 +00:00
|
|
|
}
|
2018-08-19 11:46:05 +00:00
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-08-19 11:46:05 +00:00
|
|
|
|
2018-08-20 14:50:35 +00:00
|
|
|
return cellrelmatrix(c, i) * get_corner_position(c->move(i), (cellwalker(c, i) + wstep + (which?-1:2)).spin);
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX hyperpoint midcorner(cell *c, int i, ld v) {
|
2018-08-20 15:26:29 +00:00
|
|
|
auto hcor = farcorner(c, i, 0);
|
|
|
|
auto tcor = get_corner_position(c, i, 3);
|
|
|
|
return mid_at(tcor, hcor, v);
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX hyperpoint get_warp_corner(cell *c, int cid) {
|
2018-08-20 15:26:29 +00:00
|
|
|
// midcorner(c, cid, .5) but sometimes easier versions exist
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_GP
|
2018-08-28 15:17:34 +00:00
|
|
|
if(GOLDBERG) return gp::get_corner_position(c, cid, 2);
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_IRR || CAP_ARCM
|
2018-08-28 15:17:34 +00:00
|
|
|
if(IRREGULAR || archimedean) return midcorner(c, cid, .5);
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2019-05-26 16:04:02 +00:00
|
|
|
return ddspin(c,cid,M_PI/S7) * xpush0(cgi.tessf/2);
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|
2019-04-08 14:16:16 +00:00
|
|
|
|
|
|
|
vector<hyperpoint> hrmap::get_vertices(cell* c) {
|
|
|
|
vector<hyperpoint> res;
|
|
|
|
for(int i=0; i<c->type; i++) res.push_back(get_corner_position(c, i, 3));
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-08-17 14:47:06 +00:00
|
|
|
}
|