arb:: support for apeirogons using '*inf'

This commit is contained in:
Zeno Rogue 2022-04-23 00:57:04 +02:00
parent c6cca03248
commit 59078497dd
4 changed files with 138 additions and 19 deletions

View File

@ -65,6 +65,9 @@ struct shape {
void build_from_angles_edges(bool is_comb);
vector<pair<int, int> > sublines;
vector<pair<ld, ld>> stretch_shear;
/** '*inf' was applied to represent an apeirogon/pseudogon */
bool apeirogonal;
/** connections repeat `repeat_value` times */
int repeat_value;
/** if a tile/edge combination may be connected to edges j1 and j2 of this, j1-j2 must be divisible by cycle_length */
int cycle_length;
@ -223,7 +226,7 @@ void shape::build_from_angles_edges(bool is_comb) {
}
matrices.push_back(at);
if(is_comb) return;
if(!eqmatrix(at, Id)) {
if(!eqmatrix(at, Id) && !apeirogonal) {
throw hr_polygon_error(matrices, id, at);
}
if(sqhypot_d(3, ctr) < 1e-2) {
@ -236,6 +239,19 @@ void shape::build_from_angles_edges(bool is_comb) {
}
if(debugflags & DF_GEOM) println(hlog, "ctr = ", ctr);
}
hyperpoint inf_point;
if(apeirogonal) {
transmatrix U = at;
for(int i=0; i<3; i++) for(int j=0; j<3; j++) U[i][j] -= Id[i][j];
hyperpoint v;
ld det = U[0][1] * U[1][0] - U[1][1] * U[0][0];
v[1] = (U[1][2] * U[0][0] - U[0][2] * U[1][0]) / det;
v[0] = (U[0][2] * U[1][1] - U[1][2] * U[0][1]) / det;
v[2] = 1;
inf_point = v;
ctr = mid(C0, tC0(at));
ctr = towards_inf(ctr, inf_point);
}
ctr = normalize(ctr);
vertices.clear();
angles.clear();
@ -274,6 +290,17 @@ void shape::build_from_angles_edges(bool is_comb) {
i++;
}
}
if(apeirogonal) {
vertices.push_back(gpushxto0(ctr) * tC0(at));
hyperpoint v = gpushxto0(ctr) * inf_point;
v /= v[2];
vertices.push_back(v);
angles.push_back(angles[0]/2);
angles[0] /= 2;
angles.push_back(0);
edges.push_back(0);
edges.push_back(0);
}
n = isize(angles);
for(int i=0; i<n; i++) {
bool left = angles[(i+1) % isize(vertices)] == 0;
@ -301,9 +328,22 @@ EX void load_tile(exp_parser& ep, arbi_tiling& c, bool unit) {
cld dist = 1;
ep.skip_white();
if(ep.eat("*")) {
int rep = ep.iparse(0);
ld frep = ep.rparse(0);
if(isinf(frep)) {
cc.apeirogonal = true;
set_flag(ginf[gArbitrary].flags, qIDEAL, true);
ep.force_eat(")");
break;
}
int rep = int(frep+.5);
int repeat_from = 0;
int repeat_to = cc.in_edges.size();
if(rep == 0) {
cc.in_edges.resize(repeat_from);
cc.in_angles.resize(repeat_from);
cc.ideal_markers.resize(repeat_from);
}
else if(rep < 0) throw hr_parse_exception("don't know how to use a negative repeat in tile definition");
for(int i=1; i<rep; i++)
for(int j=repeat_from; j<repeat_to; j++) {
cc.in_edges.push_back(cc.in_edges[j]);
@ -351,10 +391,15 @@ EX void load_tile(exp_parser& ep, arbi_tiling& c, bool unit) {
poly.params = ep.extra_params;
throw;
}
cc.connections.resize(cc.size());
int n = cc.size();
cc.connections.resize(n);
for(int i=0; i<isize(cc.connections); i++)
cc.connections[i] = connection_t{cc.id, i, false};
cc.stretch_shear.resize(cc.size(), make_pair(1, 0));
if(cc.apeirogonal) {
cc.connections[n-2].eid = n-1;
cc.connections[n-1].eid = n-2;
}
cc.stretch_shear.resize(n, make_pair(1, 0));
}
EX bool do_unmirror = true;
@ -919,8 +964,13 @@ EX hyperpoint get_midedge(ld len, const hyperpoint &l, const hyperpoint &r) {
else return mid(l, r);
}
EX bool is_apeirogonal(cell *c) {
if(!in()) return false;
return current_or_slided().shapes[id_of(c->master)].apeirogonal;
}
EX transmatrix get_adj(arbi_tiling& c, int t, int dl, int t1, int xdl) {
auto& sh = c.shapes[t];
int dr = gmod(dl+1, sh.size());

View File

@ -38,6 +38,7 @@ static const int POLY_PRINTABLE = (1<<25); // these walls are printable
static const int POLY_FAT = (1<<26); // fatten this model in WRL export (used for Rug)
static const int POLY_SHADE_TEXTURE = (1<<27); // texture has 'z' coordinate for shading
static const int POLY_ONE_LEVEL = (1<<28); // only one level of the universal cover in SL(2,R)
static const int POLY_APEIROGONAL = (1<<29); // only vertices indexed up to she are drawn as the boundary
/** \brief A graphical element that can be drawn. Objects are not drawn immediately but rather queued.
*
@ -71,6 +72,8 @@ struct dqi_poly : drawqueueitem {
int offset;
/** \brief how many vertices in the model */
int cnt;
/** cnt for POLY_APEIROGONAL */
int apeiro_cnt;
/** \brief the offset in the texture vertices */
int offset_texture;
/** \brief outline color */
@ -759,6 +762,7 @@ void dqi_poly::gldraw() {
}
if(outline && !tinf) {
if(flags & POLY_APEIROGONAL) cnt = apeiro_cnt;
glhr::color2(outline);
glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE);
glhr::set_depthwrite(model_needs_depth() && prio != PPR::TRANSPARENT_SHADOW && prio != PPR::EUCLIDEAN_SKY);
@ -2575,6 +2579,7 @@ EX dqi_poly& queuepolyat(const shiftmatrix& V, const hpcshape& h, color_t col, P
ptd.tinf = h.tinf;
if(neon_mode != eNeon::none && (h.flags & POLY_TRIANGLES))
ptd.tinf = nullptr;
ptd.apeiro_cnt = h.she - h.s;
ptd.offset_texture = h.texture_offset;
ptd.intester = h.intester;
return ptd;

View File

@ -84,6 +84,9 @@ void geometry_information::init_floorshapes() {
for(auto sh: all_escher_floorshapes) sh->id = ids++;
}
/** matrixitem::second[2][2] == APEIROGONAL_INVALID is used to denote a matrix that uses fake apeirogon vertices and thus should not be used */
const ld APEIROGONAL_INVALID = -2;
typedef pair<transmatrix, vector<transmatrix>> matrixitem;
struct mesher {
@ -239,22 +242,35 @@ void geometry_information::bshape2(hpcshape& sh, PPR prio, int shapeid, matrixli
bshape(sh, prio);
/* in case of apeirogonal shapes, we may need to cyclically rotate */
bool apeirogonal = false;
vector<hyperpoint> backup;
for(int r=0; r<nsym; r+=osym/rots) {
for(hyperpoint h: lst) {
hyperpoint nh = may_kleinize(h);
int mapped = 0;
int invalid = 0;
for(auto& m: matrices) {
hyperpoint z = m.first * h;
if(z[0] > -1e-5 && z[1] > -1e-5 && z[2] > -1e-5) {
if(m.second[r][2][2] == APEIROGONAL_INVALID) invalid++;
nh = m.second[r] * z, mapped++;
}
}
if(mapped == 0) printf("warning: not mapped (shapeid %d)\n", shapeid);
hpcpush(mid(nh, nh));
if(invalid) {
apeirogonal = true;
for(int i=last->s; i<isize(hpc); i++) backup.push_back(hpc[i]);
hpc.resize(last->s);
first = true;
}
if(!invalid) hpcpush(mid(nh, nh));
}
}
hpcpush(hpc[last->s]);
for(auto& b: backup) hpcpush(b);
if(!apeirogonal) hpcpush(hpc[last->s]);
}
template<class T> void sizeto(T& t, int n) {
@ -334,6 +350,16 @@ void geometry_information::bshape_regular(floorshape &fsh, int id, int sides, ld
namespace irr { void generate_floorshapes(); }
#endif
void geometry_information::finish_apeirogon(hyperpoint center) {
last->flags |= POLY_APEIROGONAL;
last->she = isize(hpc);
hyperpoint b = hpc.back();
for(int i=1; i<15; i++) hpcpush(towards_inf(b, center, i));
hpcpush(normalize(1e-9 * C0 + center));
for(int i=15; i>=1; i--) hpcpush(towards_inf(hpc[last->s], center, i));
hpcpush(hpc[last->s]);
}
// !siid equals pseudohept(c)
void geometry_information::generate_floorshapes_for(int id, cell *c, int siid, int sidir) {
@ -384,6 +410,7 @@ void geometry_information::generate_floorshapes_for(int id, cell *c, int siid, i
vector<hyperpoint> cornerlist;
int cor = c->type;
bool apeirogonal = false;
if(&fsh == &shTriheptaFloor) {
if(!siid) {
@ -446,7 +473,8 @@ void geometry_information::generate_floorshapes_for(int id, cell *c, int siid, i
min_dist = dist;
}
ld dist = min_dist * (1 - 3 / sca) * arb::current_or_slided().boundary_ratio;
auto &ac = arb::current_or_slided();
ld dist = min_dist * (1 - 3 / sca) * ac.boundary_ratio;
ld area = 0;
for(int j=0; j<cor; j++) {
@ -454,12 +482,23 @@ void geometry_information::generate_floorshapes_for(int id, cell *c, int siid, i
hyperpoint last = kleinize(actual[j?j-1:cor-1]);
area += current[0] * last[1] - last[0] * current[1];
}
if(area < 0) dist = -dist;
if(area < 0) dist = -dist;
int id = arb::id_of(c->master);
auto& sh = ac.shapes[id];
apeirogonal = sh.apeirogonal;
for(int j=0; j<cor; j++) {
hyperpoint last = actual[j?j-1:cor-1];
hyperpoint current = ypush(1e-6 * randd()) * xpush(1e-6) * actual[j];
hyperpoint next = actual[j<cor-1?j+1:0];
if(apeirogonal) {
if(j == 0) last = arb::get_adj(arb::current_or_slided(), id, cor-1, id, cor-2) * actual[cor-3];
if(j == cor-2) next = arb::get_adj(arb::current_or_slided(), id, cor-2, id, cor-1) * actual[1];
if(j == cor-1) { cornerlist.push_back(sh.vertices.back()); continue; }
}
auto T = gpushxto0(current);
last = T * last;
next = T * next;
@ -491,6 +530,10 @@ void geometry_information::generate_floorshapes_for(int id, cell *c, int siid, i
else if(&fsh == &shTriheptaFloor && cor == 4 && siid)
/* trihepta floors generate digons too */
for(int i=0; i<=cor; i++) hpcpush(spin((i&1) ? .1 : -.1) * cornerlist[i%cor]);
else if(apeirogonal) {
for(int i=0; i<=cor-2; i++) hpcpush(cornerlist[i]);
finish_apeirogon(cornerlist.back());
}
else
for(int i=0; i<=cor; i++) hpcpush(cornerlist[i%cor]);
@ -544,7 +587,8 @@ void geometry_information::generate_floorshapes_for(int id, cell *c, int siid, i
auto& m = (siid && geosupport_football() == 2) ? hex_matrices : hept_matrices;
int cor = c->type;
bool apeirogonal = arb::is_apeirogonal(c);
m.n.sym = cor;
int v = sidir+siid;
@ -556,13 +600,24 @@ void geometry_information::generate_floorshapes_for(int id, cell *c, int siid, i
hyperpoint center = hpxy(0,0);
for(int cid=0; cid<cor; cid++) {
hyperpoint nlcorner = get_corner_position(c, (d+cid+v+1) % cor, 3 / fsh.scale * (ii ? 1/SHADMUL : 1));
hyperpoint nrcorner = get_corner_position(c, (d+cid+v+2) % cor, 3 / fsh.scale * (ii ? 1/SHADMUL : 1));
hyperpoint nfar = nearcorner(c, (d+cid+v+1) % cor);
hyperpoint nlfar = farcorner(c, (d+cid+v+1) % cor, 0);
hyperpoint nrfar = farcorner(c, (d+cid+v+1) % cor, 1);
int dcidv = d + cid + v;
if(apeirogonal) dcidv--;
int dcidv1 = gmod(dcidv + 1, cor);
int dcidv2 = gmod(dcidv + 2, cor);
if(apeirogonal && dcidv1 >= cor-2) {
for(int j: {0,1,2,3})
m.v[i+j].second[cid][2][2] = APEIROGONAL_INVALID;
continue;
}
hyperpoint nlcorner = get_corner_position(c, dcidv1, 3 / fsh.scale * (ii ? 1/SHADMUL : 1));
hyperpoint nrcorner = get_corner_position(c, dcidv2, 3 / fsh.scale * (ii ? 1/SHADMUL : 1));
hyperpoint nfar = nearcorner(c, dcidv1);
hyperpoint nlfar = farcorner(c, dcidv1, 0);
hyperpoint nrfar = farcorner(c, dcidv1, 1);
m.v[i].second[cid] = build_matrix(center, nlcorner, nrcorner,C02);
m.v[i+1].second[cid] = build_matrix(nfar, nlcorner, nrcorner,C02);
m.v[i+2].second[cid] = build_matrix(nfar, nlcorner, nlfar,C02);
@ -572,8 +627,16 @@ void geometry_information::generate_floorshapes_for(int id, cell *c, int siid, i
i += 4;
}
if(i != isize(m.v)) printf("warning: i=%d sm=%d\n", i, isize(m.v));
if(i != isize(m.v)) printf("warning: i=%d sm=%d\n", i, isize(m.v));
bshape2((ii?fsh.shadow:fsh.b)[id], fsh.prio, (fsh.shapeid2 && geosupport_football() < 2) ? fsh.shapeid2 : siid?fsh.shapeid0:fsh.shapeid1, m);
if(apeirogonal) {
int id = arb::id_of(c->master);
auto &ac = arb::current_or_slided();
auto& sh = ac.shapes[id];
hpcpush(arb::get_adj(arb::current_or_slided(), id, cor-2, id, cor-1) * hpc[last->s]);
finish_apeirogon(sh.vertices.back());
}
}
}
}

View File

@ -454,6 +454,7 @@ hpcshape
void generate_floorshapes_for(int id, cell *c, int siid, int sidir);
void generate_floorshapes();
void make_floor_textures_here();
void finish_apeirogon(hyperpoint center);
vector<hyperpoint> get_shape(hpcshape sh);
void add_cone(ld z0, const vector<hyperpoint>& vh, ld z1);