1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-23 21:07:17 +00:00

used OOP for get_corner_position

This commit is contained in:
Zeno Rogue 2021-06-14 09:38:05 +02:00
parent 42fc2c44a7
commit 8b306c765e
7 changed files with 95 additions and 84 deletions

View File

@ -805,6 +805,12 @@ struct hrmap_arbi : hrmap {
int shvid(cell *c) override { int shvid(cell *c) override {
return id_of(c->master); return id_of(c->master);
} }
hyperpoint get_corner(cell *c, int cid, ld cf) override {
auto& sh = arb::current_or_slided().shapes[arb::id_of(c->master)];
return normalize(C0 + (sh.vertices[gmod(cid, c->type)] - C0) * 3 / cf);
}
}; };
EX hrmap *new_map() { return new hrmap_arbi; } EX hrmap *new_map() { return new hrmap_arbi; }

View File

@ -787,6 +787,28 @@ struct hrmap_archimedean : hrmap {
if(ac.regular && id>=2 && id < 2*ac.N) id &= 1; if(ac.regular && id>=2 && id < 2*ac.N) id &= 1;
return id; return id;
} }
hyperpoint get_corner(cell *c, int cid, ld cf) override {
auto &ac = arcm::current_or_fake();
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);
}
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));
}
return C0;
}
}; };
EX hrmap *new_map() { return new hrmap_archimedean; } EX hrmap *new_map() { return new hrmap_archimedean; }

View File

@ -440,6 +440,14 @@ EX namespace bt {
return 0; return 0;
} }
hyperpoint get_corner(cell *c, int cid, ld cf) override {
if(WDIM == 3) {
println(hlog, "get_corner_position called");
return C0;
}
return mid_at_actual(bt::get_horopoint(bt::get_corner_horo_coordinates(c, cid)), 3/cf);
}
int updir_at(heptagon *h) { int updir_at(heptagon *h) {
if(geometry != gBinaryTiling) return updir(); if(geometry != gBinaryTiling) return updir();
else if(type_of(h) == 6) return bd_down; else if(type_of(h) == 6) return bd_down;

View File

@ -62,6 +62,7 @@ struct hrmap {
virtual void find_cell_connection(cell *c, int d); virtual void find_cell_connection(cell *c, int d);
virtual int shvid(cell *c) { return 0; } virtual int shvid(cell *c) { return 0; }
virtual hyperpoint get_corner(cell *c, int cid, ld cf=3) { return C0; }
}; };
/** hrmaps which are based on regular non-Euclidean 2D tilings, possibly quotient /** hrmaps which are based on regular non-Euclidean 2D tilings, possibly quotient
@ -80,6 +81,7 @@ struct hrmap_standard : hrmap {
double spacedist(cell *c, int i) override; double spacedist(cell *c, int i) override;
void find_cell_connection(cell *c, int d) override; void find_cell_connection(cell *c, int d) override;
virtual int shvid(cell *c); virtual int shvid(cell *c);
virtual hyperpoint get_corner(cell *c, int cid, ld cf) override;
}; };
void clearfrom(heptagon*); void clearfrom(heptagon*);

View File

@ -520,39 +520,12 @@ EX hyperpoint randomPointIn(int t) {
*/ */
EX hyperpoint get_corner_position(cell *c, int cid, ld cf IS(3)) { EX hyperpoint get_corner_position(cell *c, int cid, ld cf IS(3)) {
return currentmap->get_corner(c, cid, cf);
}
hyperpoint hrmap_standard::get_corner(cell *c, int cid, ld cf) {
#if CAP_GP #if CAP_GP
if(GOLDBERG) return gp::get_corner_position(c, cid, cf); if(GOLDBERG) return gp::get_corner_position(c, cid, cf);
if(UNTRUNCATED) {
cell *c1 = gp::get_mapped(c);
cellwalker cw(c1, cid*2);
if(!gp::untruncated_shift(c)) cw--;
hyperpoint h = UIU(nearcorner(c1, cw.spin));
return mid_at_actual(h, 3/cf);
}
if(UNRECTIFIED) {
cell *c1 = gp::get_mapped(c);
hyperpoint h = UIU(nearcorner(c1, cid));
return mid_at_actual(h, 3/cf);
}
if(WARPED) {
int sh = gp::untruncated_shift(c);
cell *c1 = gp::get_mapped(c);
if(sh == 2) {
cellwalker cw(c, cid);
hyperpoint h1 = UIU(tC0(currentmap->adj(c1, cid)));
cw--;
hyperpoint h2 = UIU(tC0(currentmap->adj(c1, cw.spin)));
hyperpoint h = mid(h1, h2);
return mid_at_actual(h, 3/cf);
}
else {
cellwalker cw(c1, cid*2);
if(!gp::untruncated_shift(c)) cw--;
hyperpoint h = UIU(nearcorner(c1, cw.spin));
h = mid(h, C0);
return mid_at_actual(h, 3/cf);
}
}
#endif #endif
#if CAP_IRR #if CAP_IRR
if(IRREGULAR) { if(IRREGULAR) {
@ -560,41 +533,6 @@ EX hyperpoint get_corner_position(cell *c, int cid, ld cf IS(3)) {
return mid_at_actual(vs.vertices[cid], 3/cf); return mid_at_actual(vs.vertices[cid], 3/cf);
} }
#endif #endif
#if CAP_BT
if(kite::in()) return kite::get_corner(c, cid, cf);
if(bt::in()) {
if(WDIM == 3) {
println(hlog, "get_corner_position called");
return C0;
}
return mid_at_actual(bt::get_horopoint(bt::get_corner_horo_coordinates(c, cid)), 3/cf);
}
#endif
#if CAP_ARCM
if(arcm::in()) {
auto &ac = arcm::current_or_fake();
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);
}
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));
}
}
#endif
if(arb::in()) {
auto& sh = arb::current_or_slided().shapes[arb::id_of(c->master)];
return normalize(C0 + (sh.vertices[gmod(cid, c->type)] - C0) * 3 / cf);
}
if(PURE) { if(PURE) {
return ddspin(c,cid,M_PI/S7) * xpush0(cgi.hcrossf * 3 / cf); return ddspin(c,cid,M_PI/S7) * xpush0(cgi.hcrossf * 3 / cf);
} }
@ -674,7 +612,7 @@ EX hyperpoint nearcorner(cell *c, int i) {
} }
if(kite::in()) { if(kite::in()) {
if(approx_nearcorner) if(approx_nearcorner)
return kite::get_corner(c, i, 3) + kite::get_corner(c, i+1, 3) - C0; return currentmap->get_corner(c, i, 3) + currentmap->get_corner(c, i+1, 3) - C0;
else else
return calc_relative_matrix(c->cmove(i), c, C0) * C0; return calc_relative_matrix(c->cmove(i), c, C0) * C0;
} }

View File

@ -1280,6 +1280,41 @@ EX namespace gp {
int shvid(cell *c) override { int shvid(cell *c) override {
return gp::get_plainshape_id(c); return gp::get_plainshape_id(c);
} }
hyperpoint get_corner(cell *c, int cid, ld cf) override {
if(UNTRUNCATED) {
cell *c1 = gp::get_mapped(c);
cellwalker cw(c1, cid*2);
if(!gp::untruncated_shift(c)) cw--;
hyperpoint h = UIU(nearcorner(c1, cw.spin));
return mid_at_actual(h, 3/cf);
}
if(UNRECTIFIED) {
cell *c1 = gp::get_mapped(c);
hyperpoint h = UIU(nearcorner(c1, cid));
return mid_at_actual(h, 3/cf);
}
if(WARPED) {
int sh = gp::untruncated_shift(c);
cell *c1 = gp::get_mapped(c);
if(sh == 2) {
cellwalker cw(c, cid);
hyperpoint h1 = UIU(tC0(currentmap->adj(c1, cid)));
cw--;
hyperpoint h2 = UIU(tC0(currentmap->adj(c1, cw.spin)));
hyperpoint h = mid(h1, h2);
return mid_at_actual(h, 3/cf);
}
else {
cellwalker cw(c1, cid*2);
if(!gp::untruncated_shift(c)) cw--;
hyperpoint h = UIU(nearcorner(c1, cw.spin));
h = mid(h, C0);
return mid_at_actual(h, 3/cf);
}
}
return C0;
}
}; };
EX hrmap* new_inverse() { return new hrmap_inverse; } EX hrmap* new_inverse() { return new hrmap_inverse; }

View File

@ -61,23 +61,6 @@ const ld kite_center = up;
EX pshape getshape(heptagon *h) { return pshape(h->s); } EX pshape getshape(heptagon *h) { return pshape(h->s); }
EX hyperpoint get_corner(cell *c, int d, ld cf) {
bool kite = getshape(c->master) == pKite;
int t = kite ? 1 : -1;
ld shf = kite ? kite_center : dart_center;
ld mul = 3/cf;
switch(d & 3) {
case 0: return mhpxy(-mul, (shf)*mul);
case 1: return mhpxy(0, (shf-down)*mul);
case 2: return mhpxy(+mul, shf*mul);
case 3: return mhpxy(0, (shf + t*up)*mul);
}
return C0; /* unreachable! */
}
EX pair<vector<vector<hyperpoint>>, vector<vector<ld>>> make_walls() { EX pair<vector<vector<hyperpoint>>, vector<vector<ld>>> make_walls() {
vector<vector<hyperpoint>> kv; vector<vector<hyperpoint>> kv;
@ -152,6 +135,23 @@ struct hrmap_kite : hrmap {
kite::find_cell_connection(c, d); kite::find_cell_connection(c, d);
} }
hyperpoint get_corner(cell *c, int cid, ld cf) override {
bool kite = getshape(c->master) == pKite;
int t = kite ? 1 : -1;
ld shf = kite ? kite_center : dart_center;
ld mul = 3/cf;
switch(cid & 3) {
case 0: return mhpxy(-mul, (shf)*mul);
case 1: return mhpxy(0, (shf-down)*mul);
case 2: return mhpxy(+mul, shf*mul);
case 3: return mhpxy(0, (shf + t*up)*mul);
}
return C0; /* unreachable! */
}
int shvid(cell *c) override { int shvid(cell *c) override {
return kite::getshape(c->master); return kite::getshape(c->master);
} }