From 2a7d93270395e8c4f44894c49c2f06656a0f3364 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 8 Jul 2021 20:34:49 +0200 Subject: [PATCH] reg3:: subcubes:: neater again --- reg3.cpp | 68 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/reg3.cpp b/reg3.cpp index d0d2bdb7..4c08197c 100644 --- a/reg3.cpp +++ b/reg3.cpp @@ -320,45 +320,47 @@ EX namespace reg3 { for(co[1]=-sub; co[1]<=sub; co[1]+=s) for(co[2]=-sub; co[2]<=sub; co[2]+=s) if(((co[0]^co[1]^1)&1) && ((co[0]^co[2]^1)&1)) { - vector dirs; - vector dirlimits; - vector mirrors; hyperpoint ctr = Hypc; ctr[3] = vz * sub; + + struct direction { + hyperpoint dir; + int limit; + transmatrix mirror; + void flip() { dir = -dir; limit = 200 - limit; } + }; + + array di; int mi = 0; - for(int i=0; i<3; i++) - if(co[i] != -sub && co[i] != +sub) { - dirs.push_back(ctangent(i, vx)); - dirlimits.push_back(999); - mirrors.push_back(cpush(i, -step/2) * cmirror(i) * cpush(i, step/2)); - } for(int i=0; i<3; i++) { ctr[i] += co[i] * vx; - if(co[i] == sub) { - mi++; - dirs.push_back(ctangent(i, vx)); - dirlimits.push_back(0); - mirrors.push_back(cpush(i, +step/2) * cmirror(i) * cpush(i, -step/2)); + auto& dii = di[i]; + if(co[i] >= 0) { + dii.dir = ctangent(i, vx); + dii.limit = sub - co[i]; + dii.mirror = cpush(i, +step/2) * cmirror(i) * cpush(i, -step/2); } - else if(co[i] == -sub) { - mi++; - dirs.push_back(ctangent(i, -vx)); - dirlimits.push_back(0); - mirrors.push_back(cpush(i, -step/2) * cmirror(i) * cpush(i, +step/2)); + else { + dii.dir = ctangent(i, -vx); + dii.limit = co[i] + sub; + dii.mirror = cpush(i, -step/2) * cmirror(i) * cpush(i, +step/2); } + if(dii.limit == 0) mi++; } + sort(di.begin(), di.end(), [] (direction& d1, direction& d2) { return d1.limit > d2.limit; }); + cgi.subshapes.emplace_back(); auto &ss = cgi.subshapes.back(); auto pt = [&] (ld x, ld y, ld z) { transmatrix M = Id; - if(x > dirlimits[0]) x = -x, M = mirrors[0] * M; - if(y > dirlimits[1]) y = -y, M = mirrors[1] * M; - if(z > dirlimits[2]) z = -z, M = mirrors[2] * M; - return normalize(M * (ctr + dirs[0] * x + dirs[1] * y + dirs[2] * z)); + if(x > di[0].limit) x = -x, M = di[0].mirror * M; + if(y > di[1].limit) y = -y, M = di[1].mirror * M; + if(z > di[2].limit) z = -z, M = di[2].mirror * M; + return normalize(M * (ctr + di[0].dir * x + di[1].dir * y + di[2].dir * z)); }; auto add_face = [&] (std::initializer_list vh) { @@ -374,17 +376,17 @@ EX namespace reg3 { add_face({pt(0,.5,s), pt(.5,0,s), pt(0,-.5,s), pt(-.5,0,s)}); else add_face({pt(-1,-1,s), pt(-1,+1,s), pt(+1,+1,s), pt(+1,-1,s)}); - tie(dirs[0], dirs[1], dirs[2]) = make_tuple(dirs[1], dirs[2], dirs[0]); + tie(di[0], di[1], di[2]) = make_tuple(di[1], di[2], di[0]); } } if(bch) for(int u=0; u<8; u++) { - for(int j=0; j<3; j++) if((u>>j)&1) dirs[j] = -dirs[j]; + for(int j=0; j<3; j++) if((u>>j)&1) di[j].flip(); add_face({pt(0,.5,1), pt(0,1,.5), pt(.5,1,0), pt(1,.5,0), pt(1,0,.5), pt(.5,0,1)}); - for(int j=0; j<3; j++) if((u>>j)&1) dirs[j] = -dirs[j]; + for(int j=0; j<3; j++) if((u>>j)&1) di[j].flip(); } } else if(mi == 1) { - auto& M = mirrors[2]; + auto& M = di[2].mirror; for(int s: {-1, 1}) { if(bch) add_face({pt(0,h,s), pt(h,0,s), pt(0,-h,s), pt(-h,0,s)}); @@ -395,23 +397,23 @@ EX namespace reg3 { add_face({pt(1,0,-.5), pt(1,-.5,0), M*pt(1,0,-.5), pt(1,.5,0)}); else add_face({pt(-1,-1,-1), pt(-1,+1,-1), pt(-1,+1,+1), pt(-1,-1,+1)}); - tie(dirs[0], dirs[1]) = make_tuple(dirs[1], -dirs[0]); + tie(di[0], di[1]) = make_tuple(di[1], di[0]); di[0].flip(); } } if(bch) for(ld s: {-1, 1}) for(int i=0; i<4; i++) { add_face({pt(0,.5,s), pt(0,1,s/2), pt(.5,1,0), pt(1,.5,0), pt(1,0,s/2), pt(.5,0,s)}); - tie(dirs[0], dirs[1]) = make_tuple(dirs[1], -dirs[0]); + tie(di[0], di[1]) = make_tuple(di[1], di[0]); di[0].flip(); } } else { - transmatrix spi = mi == 2 ? mirrors[1] * mirrors[2] : mirrors[0] * mirrors[1]; + transmatrix spi = mi == 2 ? di[1].mirror * di[2].mirror : di[0].mirror * di[1].mirror; if(cgi.loop == 5) spi = spi * spi; vector spi_power = {Id}; for(int i=1; i