mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-01-11 18:00:34 +00:00
relative_matrix and adj changed
This commit is contained in:
parent
f3beb9d2ac
commit
7e8ede4bd6
@ -170,9 +170,9 @@ struct hrmap_asonov : hrmap {
|
||||
return child;
|
||||
}
|
||||
|
||||
transmatrix adj(cell *c, int i) override { return adjmatrix(i); }
|
||||
transmatrix adj(heptagon *h, int i) override { return adjmatrix(i); }
|
||||
|
||||
virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
for(int a=0; a<S7; a++) if(h2 == h1->move(a)) return adjmatrix(a);
|
||||
return coord_to_matrix(coords[h2], coords[h1]);
|
||||
}
|
||||
|
@ -434,11 +434,6 @@ EX namespace binary {
|
||||
}
|
||||
}
|
||||
|
||||
// hrmap_standard overrides hrmap's default, override it back
|
||||
virtual transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hint) override {
|
||||
return relative_matrix(c2->master, c1->master);
|
||||
}
|
||||
|
||||
int updir_at(heptagon *h) {
|
||||
if(geometry != gBinaryTiling) return updir();
|
||||
else if(type_of(h) == 6) return bd_down;
|
||||
@ -447,7 +442,7 @@ EX namespace binary {
|
||||
else throw "unknown updir";
|
||||
}
|
||||
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
if(gmatrix0.count(h2->c7) && gmatrix0.count(h1->c7))
|
||||
return inverse(gmatrix0[h1->c7]) * gmatrix0[h2->c7];
|
||||
transmatrix gm = Id, where = Id;
|
||||
@ -517,7 +512,7 @@ EX namespace binary {
|
||||
return -(d+2)*M_PI/4;
|
||||
}
|
||||
|
||||
const transmatrix adj(heptagon *h, int dir) {
|
||||
transmatrix adj(heptagon *h, int dir) {
|
||||
if(geometry == gBinaryTiling) switch(dir) {
|
||||
case bd_up: return xpush(-log(2));
|
||||
case bd_left: return parabolic(-1);
|
||||
@ -545,8 +540,6 @@ EX namespace binary {
|
||||
|
||||
const transmatrix iadj(heptagon *h, int dir) { heptagon *h1 = h->cmove(dir); return adj(h1, h->c.spin(dir)); }
|
||||
|
||||
transmatrix adj(cell *c, int dir) override { return adj(c->master, dir); }
|
||||
|
||||
void virtualRebase(heptagon*& base, transmatrix& at) override {
|
||||
|
||||
while(true) {
|
||||
|
18
cell.cpp
18
cell.cpp
@ -27,15 +27,17 @@ struct hrmap {
|
||||
printf("create_step called unexpectedly\n"); exit(1);
|
||||
return NULL;
|
||||
}
|
||||
virtual struct transmatrix relative_matrix(heptagon *h2, heptagon *h1) {
|
||||
virtual struct transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) {
|
||||
printf("relative_matrix called unexpectedly\n");
|
||||
return Id;
|
||||
}
|
||||
virtual struct transmatrix relative_matrix(cell *c2, cell *c1, const struct hyperpoint& point_hint) {
|
||||
return relative_matrix(c2->master, c1->master);
|
||||
virtual struct transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& hint) {
|
||||
return relative_matrix(c2->master, c1->master, hint);
|
||||
}
|
||||
virtual struct transmatrix adj(cell *c, int i);
|
||||
virtual struct transmatrix adj(cell *c, int i) { return adj(c->master, i); }
|
||||
virtual struct transmatrix adj(heptagon *h, int i);
|
||||
struct transmatrix iadj(cell *c, int i) { cell *c1 = c->cmove(i); return adj(c1, c->c.spin(i)); }
|
||||
transmatrix iadj(heptagon *h, int d) { return adj(h->cmove(d), h->c.spin(d)); }
|
||||
virtual void draw() {
|
||||
printf("undrawable\n");
|
||||
}
|
||||
@ -71,11 +73,11 @@ struct hrmap {
|
||||
/** hrmaps which are based on regular non-Euclidean 2D tilings, possibly quotient */
|
||||
struct hrmap_standard : hrmap {
|
||||
void draw() override;
|
||||
transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hint) override;
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override;
|
||||
transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& hint) override;
|
||||
heptagon *create_step(heptagon *h, int direction) override;
|
||||
transmatrix adj(cell *c, int d) override;
|
||||
transmatrix adj(heptagon *h, int d);
|
||||
transmatrix iadj(heptagon *h, int d) { return adj(h->cmove(d), h->c.spin(d)); }
|
||||
transmatrix adj(heptagon *h, int d) override;
|
||||
ld spin_angle(cell *c, int d) override;
|
||||
double spacedist(cell *c, int i) override;
|
||||
};
|
||||
@ -98,7 +100,7 @@ struct hrmap_hyperbolic : hrmap_standard {
|
||||
};
|
||||
#endif
|
||||
|
||||
transmatrix hrmap::adj(cell *c, int i) { return calc_relative_matrix(c->cmove(i), c, C0); }
|
||||
transmatrix hrmap::adj(heptagon *h, int i) { return relative_matrix(h->cmove(i), h, C0); }
|
||||
|
||||
vector<cell*>& hrmap::allcells() {
|
||||
static vector<cell*> default_allcells;
|
||||
|
@ -2731,7 +2731,7 @@ EX namespace sword {
|
||||
cell *best = NULL;
|
||||
ld bdist = HUGE_VAL;
|
||||
for(int i=0; i<S7; i++) {
|
||||
ld dist = hdist(sd.T * xpush0(rev?-0.1:0.1), tC0(currentmap->relative_matrix(c->move(i)->master, c->master)));
|
||||
ld dist = hdist(sd.T * xpush0(rev?-0.1:0.1), tC0(currentmap->relative_matrix(c->move(i)->master, c->master, C0)));
|
||||
if(dist < bdist) bdist = dist, best = c->move(i);
|
||||
}
|
||||
return best;
|
||||
@ -2776,7 +2776,7 @@ EX namespace sword {
|
||||
d.angle = ((s2*sword_angles/t2 - s1*sword_angles/t1) + sword_angles/2 + d.angle) % sword_angles;
|
||||
}
|
||||
else {
|
||||
transmatrix T = currentmap->relative_matrix(c1->master, c2->master);
|
||||
transmatrix T = currentmap->relative_matrix(c1->master, c2->master, C0);
|
||||
T = gpushxto0(tC0(T)) * T;
|
||||
d.T = T * d.T;
|
||||
fixmatrix(d.T);
|
||||
|
@ -597,9 +597,9 @@ struct hrmap_crystal : hrmap_standard {
|
||||
return xpush(999);
|
||||
}
|
||||
|
||||
virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
if(!crystal3()) return hrmap::relative_matrix(h2, h1);
|
||||
return relative_matrix(h2->c7, h1->c7, C0);
|
||||
virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
if(!crystal3()) return hrmap::relative_matrix(h2, h1, hint);
|
||||
return relative_matrix(h2->c7, h1->c7, hint);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
@ -709,8 +709,10 @@ EX namespace euclid3 {
|
||||
return eupush3(v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
if(twisted) {
|
||||
if(h1 == h2) return Id;
|
||||
for(int s=0; s<S7; s++) if(h2 == h1->move(s)) return adj(h1, s);
|
||||
coord c1 = ispacemap[h1];
|
||||
coord c2 = ispacemap[h2];
|
||||
transmatrix T = warppush(c2 - c1);
|
||||
|
2
game.cpp
2
game.cpp
@ -7660,7 +7660,7 @@ EX vector<cell*> adj_minefield_cells(cell *c) {
|
||||
cell *c1 = cl.lst[i];
|
||||
bool shares = false;
|
||||
if(c != c1) {
|
||||
transmatrix T = currentmap->relative_matrix(c1->master, c->master);
|
||||
transmatrix T = currentmap->relative_matrix(c1->master, c->master, C0);
|
||||
for(hyperpoint h: vertices) for(hyperpoint h2: vertices)
|
||||
if(hdist(h, T * h2) < 1e-6) shares = true;
|
||||
if(shares) res.push_back(c1);
|
||||
|
@ -55,8 +55,8 @@ EX transmatrix master_relative(cell *c, bool get_inverse IS(false)) {
|
||||
return pispin * Id;
|
||||
}
|
||||
|
||||
EX transmatrix calc_relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hint) {
|
||||
return currentmap->relative_matrix(c2, c1, point_hint);
|
||||
EX transmatrix calc_relative_matrix(cell *c2, cell *c1, const hyperpoint& hint) {
|
||||
return currentmap->relative_matrix(c2, c1, hint);
|
||||
}
|
||||
|
||||
// target, source, direction from source to target
|
||||
@ -73,13 +73,21 @@ transmatrix hrmap_standard::adj(heptagon *h, int d) {
|
||||
return T;
|
||||
}
|
||||
|
||||
transmatrix hrmap_standard::relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hint) {
|
||||
transmatrix hrmap_standard::relative_matrix(cell *c2, cell *c1, const hyperpoint& hint) {
|
||||
|
||||
heptagon *h1 = c1->master;
|
||||
transmatrix gm = master_relative(c1, true);
|
||||
heptagon *h2 = c2->master;
|
||||
transmatrix where = master_relative(c2);
|
||||
|
||||
transmatrix U = relative_matrix(h2, h1, hint);
|
||||
|
||||
return gm * U * where;
|
||||
}
|
||||
|
||||
transmatrix hrmap_standard::relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) {
|
||||
|
||||
transmatrix gm = Id, where = Id;
|
||||
// always add to last!
|
||||
//bool hsol = false;
|
||||
//transmatrix sol;
|
||||
@ -101,12 +109,12 @@ transmatrix hrmap_standard::relative_matrix(cell *c2, cell *c1, const hyperpoint
|
||||
transmatrix S = adj(h1, d);
|
||||
if(hm == h2) {
|
||||
transmatrix T1 = gm * S * where;
|
||||
auto curdist = hdist(tC0(T1), point_hint);
|
||||
auto curdist = hdist(tC0(T1), hint);
|
||||
if(curdist < bestdist) T = T1, bestdist = curdist;
|
||||
}
|
||||
if(geometry != gMinimal) for(int e=0; e<S7; e++) if(hm->move(e) == h2) {
|
||||
transmatrix T1 = gm * S * adj(hm, e) * where;
|
||||
auto curdist = hdist(tC0(T1), point_hint);
|
||||
auto curdist = hdist(tC0(T1), hint);
|
||||
if(curdist < bestdist) T = T1, bestdist = curdist;
|
||||
}
|
||||
}
|
||||
@ -130,7 +138,7 @@ transmatrix hrmap_standard::relative_matrix(cell *c2, cell *c1, const hyperpoint
|
||||
auto hm = h1->cmove(d3);
|
||||
if(visited.count(hm)) continue;
|
||||
visited.insert(hm);
|
||||
ld dist = crystal::space_distance(hm->c7, c2);
|
||||
ld dist = crystal::space_distance(hm->c7, h2->c7);
|
||||
hbdist[dist].emplace_back(hm, gm * adj(h1, d3));
|
||||
}
|
||||
auto &bestv = hbdist.begin()->second;
|
||||
|
@ -125,7 +125,7 @@ EX namespace dual {
|
||||
h = hpxy3(h[0]/10, h[1]/10, h[2]/10);
|
||||
ld b = HUGE_VAL;
|
||||
for(int i=0; i<S7; i++) {
|
||||
hyperpoint checked = tC0(currentmap->relative_matrix(cwt.at->cmove(i)->master, cwt.at->master));
|
||||
hyperpoint checked = tC0(currentmap->relative_matrix(cwt.at->cmove(i)->master, cwt.at->master, C0));
|
||||
ld dist = hdist(checked, h);
|
||||
if(dist < b) { b = dist; d = i; }
|
||||
}
|
||||
@ -190,7 +190,7 @@ EX namespace dual {
|
||||
return ok;
|
||||
}
|
||||
|
||||
which_dir = inverse(sword::dir[0].T) * tC0(currentmap->relative_matrix((cwt+d).cpeek()->master, cwt.at->master));
|
||||
which_dir = inverse(sword::dir[0].T) * tC0(currentmap->relative_matrix((cwt+d).cpeek()->master, cwt.at->master, C0));
|
||||
|
||||
bool lms[2][5];
|
||||
eLastmovetype lmt[2][5];
|
||||
|
@ -372,11 +372,11 @@ EX namespace solnihv {
|
||||
}
|
||||
}
|
||||
|
||||
transmatrix adj(cell *c, int d) override {
|
||||
c->cmove(d); return adjmatrix(d, c->c.spin(d));
|
||||
transmatrix adj(heptagon *h, int d) override {
|
||||
h->cmove(d); return adjmatrix(d, h->c.spin(d));
|
||||
}
|
||||
|
||||
virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
for(int i=0; i<h1->type; i++) if(h1->move(i) == h2) return adjmatrix(i, h1->c.spin(i));
|
||||
if(gmatrix0.count(h2->c7) && gmatrix0.count(h1->c7))
|
||||
return inverse(gmatrix0[h1->c7]) * gmatrix0[h2->c7];
|
||||
@ -392,10 +392,10 @@ EX namespace solnihv {
|
||||
default: throw "not nihsolv";
|
||||
}
|
||||
|
||||
while(h1->distance > h2->distance) front = front * adj(h1->c7, down), h1 = h1->cmove(down);
|
||||
while(h1->distance < h2->distance) back = iadj(h2->c7, down) * back, h2 = h2->cmove(down);
|
||||
while(coords[h1].first != coords[h2].first) front = front * adj(h1->c7, down), back = iadj(h2->c7, down) * back, h1 = h1->cmove(down), h2 = h2->cmove(down);
|
||||
while(coords[h1].second != coords[h2].second) front = front * adj(h1->c7, up), back = iadj(h2->c7, up) * back, h1 = h1->cmove(up), h2 = h2->cmove(up);
|
||||
while(h1->distance > h2->distance) front = front * adj(h1, down), h1 = h1->cmove(down);
|
||||
while(h1->distance < h2->distance) back = iadj(h2, down) * back, h2 = h2->cmove(down);
|
||||
while(coords[h1].first != coords[h2].first) front = front * adj(h1, down), back = iadj(h2, down) * back, h1 = h1->cmove(down), h2 = h2->cmove(down);
|
||||
while(coords[h1].second != coords[h2].second) front = front * adj(h1, up), back = iadj(h2, up) * back, h1 = h1->cmove(up), h2 = h2->cmove(up);
|
||||
return front * back;
|
||||
}
|
||||
|
||||
@ -850,9 +850,9 @@ EX namespace nilv {
|
||||
return child;
|
||||
}
|
||||
|
||||
transmatrix adj(cell *c, int i) override { return adjmatrix(i); }
|
||||
transmatrix adj(heptagon *h, int i) override { return adjmatrix(i); }
|
||||
|
||||
virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
for(int a=0; a<S7; a++) if(h2 == h1->move(a)) return adjmatrix(a);
|
||||
auto p = coords[h1].inverse() * coords[h2];
|
||||
for(int a=0; a<3; a++) p[a] = szgmod(p[a], nilperiod[a]);
|
||||
@ -1206,8 +1206,8 @@ EX namespace product {
|
||||
int z0;
|
||||
|
||||
struct hrmap_product : hybrid::hrmap_hybrid {
|
||||
transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hint) override {
|
||||
return in_underlying([&] { return calc_relative_matrix(where[c2].first, where[c1].first, point_hint); }) * mscale(Id, cgi.plevel * szgmod(where[c2].second - where[c1].second, csteps));
|
||||
transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& hint) override {
|
||||
return in_underlying([&] { return calc_relative_matrix(where[c2].first, where[c1].first, hint); }) * mscale(Id, cgi.plevel * szgmod(where[c2].second - where[c1].second, csteps));
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
@ -1614,7 +1614,7 @@ EX namespace rots {
|
||||
return M = spin(beta) * uxpush(distance/2) * spin(-beta+alpha);
|
||||
}
|
||||
|
||||
virtual transmatrix relative_matrix(cell *c2, cell *c1, const struct hyperpoint& point_hint) override {
|
||||
virtual transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& hint) override {
|
||||
if(c1 == c2) return Id;
|
||||
if(gmatrix0.count(c2) && gmatrix0.count(c1))
|
||||
return inverse(gmatrix0[c1]) * gmatrix0[c2];
|
||||
|
@ -319,7 +319,7 @@ struct hrmap_kite : hrmap {
|
||||
}
|
||||
}
|
||||
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
if(gmatrix0.count(h2->c7) && gmatrix0.count(h1->c7))
|
||||
return inverse(gmatrix0[h1->c7]) * gmatrix0[h2->c7];
|
||||
transmatrix gm = Id, where = Id;
|
||||
|
19
reg3.cpp
19
reg3.cpp
@ -215,7 +215,6 @@ EX namespace reg3 {
|
||||
vector<vector<transmatrix>> tmatrices;
|
||||
|
||||
transmatrix adj(heptagon *h, int d) { return tmatrices[h->fieldval][d]; }
|
||||
transmatrix adj(cell *c, int d) override { return adj(c->master, d); }
|
||||
};
|
||||
|
||||
int encode_coord(const crystal::coord& co) {
|
||||
@ -575,12 +574,12 @@ EX namespace reg3 {
|
||||
}
|
||||
}
|
||||
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
if(h1 == h2) return Id;
|
||||
int d = hr::celldistance(h2->c7, h1->c7);
|
||||
|
||||
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));
|
||||
return adj(h1, a) * relative_matrix(h2, h1->move(a), hint);
|
||||
|
||||
println(hlog, "error in hrmap_field3:::relative_matrix");
|
||||
return Id;
|
||||
@ -663,7 +662,7 @@ EX namespace reg3 {
|
||||
|
||||
celllister cl(origin->c7, 4, 100000, NULL);
|
||||
for(cell *c: cl.lst) {
|
||||
hyperpoint h = tC0(relative_matrix(c->master, origin));
|
||||
hyperpoint h = tC0(relative_matrix(c->master, origin, C0));
|
||||
close_distances[bucketer(h)] = cl.getdist(c);
|
||||
}
|
||||
}
|
||||
@ -875,19 +874,17 @@ EX namespace reg3 {
|
||||
if(quotient_map) return quotient_map->adj(h, d);
|
||||
else
|
||||
#endif
|
||||
return relative_matrix(h->cmove(d), h);
|
||||
return relative_matrix(h->cmove(d), h, C0);
|
||||
}
|
||||
|
||||
transmatrix adj(cell *c, int d) override { return adj(c->master, d); }
|
||||
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1) override {
|
||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||
auto p1 = reg_gmatrix[h1];
|
||||
auto p2 = reg_gmatrix[h2];
|
||||
transmatrix T = Id;
|
||||
if(hyperbolic) {
|
||||
dynamicval<eGeometry> g(geometry, gBinary3);
|
||||
dynamicval<hrmap*> cm(currentmap, binary_map);
|
||||
T = binary_map->relative_matrix(p2.first, p1.first);
|
||||
T = binary_map->relative_matrix(p2.first, p1.first, hint);
|
||||
}
|
||||
T = inverse(p1.second) * T * p2.second;
|
||||
if(elliptic && T[LDIM][LDIM] < 0) T = centralsym * T;
|
||||
@ -915,7 +912,7 @@ EX int celldistance(cell *c1, cell *c2) {
|
||||
|
||||
auto r = regmap();
|
||||
|
||||
hyperpoint h = tC0(r->relative_matrix(c1->master, c2->master));
|
||||
hyperpoint h = tC0(r->relative_matrix(c1->master, c2->master, C0));
|
||||
int b = bucketer(h);
|
||||
if(close_distances.count(b)) return close_distances[b];
|
||||
|
||||
@ -926,7 +923,7 @@ EX int celldistance(cell *c1, cell *c2) {
|
||||
EX bool pseudohept(cell *c) {
|
||||
auto m = regmap();
|
||||
if(sphere) {
|
||||
hyperpoint h = tC0(m->relative_matrix(c->master, regmap()->origin));
|
||||
hyperpoint h = tC0(m->relative_matrix(c->master, regmap()->origin, C0));
|
||||
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;
|
||||
|
@ -159,7 +159,7 @@ struct hrmap_spherical : hrmap_standard {
|
||||
for(int i=0; i<spherecells(); i++) verifycells(dodecahedron[i]);
|
||||
}
|
||||
|
||||
transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& point_hint) {
|
||||
transmatrix relative_matrix(cell *c2, cell *c1, const hyperpoint& hint) {
|
||||
if(!gmatrix0.count(c2) || !gmatrix0.count(c1)) {
|
||||
printf("building gmatrix0 (size=%d)\n", isize(gmatrix0));
|
||||
#if CAP_GP
|
||||
|
Loading…
Reference in New Issue
Block a user