1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-01-23 15:36:59 +00:00

3d:: *_d functions now consistently put d as the first argument

This commit is contained in:
? 2019-02-27 19:33:13 +01:00 committed by Zeno Rogue
parent 2f66a64ce3
commit 041c7af987
5 changed files with 24 additions and 24 deletions

View File

@ -3593,8 +3593,8 @@ bool model_needs_depth();
hyperpoint hpxy(ld x, ld y);
hyperpoint hpxy3(ld x, ld y, ld z);
ld sqhypot_d(const hyperpoint& h, int d);
ld hypot_d(const hyperpoint& h, int d);
ld sqhypot_d(int d, const hyperpoint& h);
ld hypot_d(int d, const hyperpoint& h);
transmatrix pushxto0(const hyperpoint& H);
transmatrix rpushxto0(const hyperpoint& H);
transmatrix spintox(const hyperpoint& H);

View File

@ -145,7 +145,7 @@ const hyperpoint Cx13 = hyperpoint(1,0,0,1.41421356237);
// through the interior, not on the surface)
// also used to verify whether a point h1 is on the hyperbolic plane by using Hypc for h2
bool zero_d(hyperpoint h, int d) {
bool zero_d(int d, hyperpoint h) {
for(int i=0; i<d; i++) if(h[i]) return false;
return true;
}
@ -161,14 +161,14 @@ ld intval(const hyperpoint &h1, const hyperpoint &h2) {
return res;
}
ld sqhypot_d(const hyperpoint& h, int d) {
ld sqhypot_d(int d, const hyperpoint& h) {
ld sum = 0;
for(int i=0; i<d; i++) sum += h[i]*h[i];
return sum;
}
ld hypot_d(const hyperpoint& h, int d) {
return sqrt(sqhypot_d(h, d));
ld hypot_d(int d, const hyperpoint& h) {
return sqrt(sqhypot_d(d, h));
}
ld zlevel(const hyperpoint &h) {
@ -415,8 +415,8 @@ transmatrix ggpushxto0(const hyperpoint& H, ld co) {
return eupush(co * H);
}
transmatrix res = Id;
if(sqhypot_d(H, DIM) < 1e-12) return res;
ld fac = (H[DIM]-1) / sqhypot_d(H, DIM);
if(sqhypot_d(DIM, H) < 1e-12) return res;
ld fac = (H[DIM]-1) / sqhypot_d(DIM, H);
for(int i=0; i<DIM; i++)
for(int j=0; j<DIM; j++)
res[i][j] += H[i] * H[j] * fac;
@ -557,7 +557,7 @@ double hdist0(const hyperpoint& mh) {
if(mh[DIM] < 1) return 0;
return acosh(mh[DIM]);
case gcEuclid: {
return hypot_d(mh, DIM);
return hypot_d(DIM, mh);
}
case gcSphere: {
ld res = mh[DIM] >= 1 ? 0 : mh[DIM] <= -1 ? M_PI : acos(mh[DIM]);

View File

@ -288,7 +288,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) {
conformal::apply_orientation(H[0], H[1]);
H[1] += 1;
double rad = sqhypot_d(H, 2);
double rad = sqhypot_d(2, H);
H /= -rad;
H[1] += .5;
@ -318,7 +318,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) {
case gcHyperbolic: {
ld zl = zlevel(H);
ret = H / H[2];
ret[2] = sqrt(1 - sqhypot_d(ret, 2));
ret[2] = sqrt(1 - sqhypot_d(2, ret));
ret = ret * (1 + (zl - 1) * ret[2]);
break;
}
@ -356,7 +356,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) {
if(pmodel == mdHyperboloid) {
ld& topz = conformal::top_z;
if(H[2] > topz) {
ld scale = sqrt(topz*topz-1) / hypot_d(H, 2);
ld scale = sqrt(topz*topz-1) / hypot_d(2, H);
H *= scale;
H[2] = topz;
}
@ -378,7 +378,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) {
ld zlev = find_zlev(H);
H = space_to_perspective(H);
H[2] = zlev;
ret = H / sqrt(1 + sqhypot_d(H, 3));
ret = H / sqrt(1 + sqhypot_d(3, H));
break;
}
@ -408,7 +408,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) {
}
H = space_to_perspective(H);
ld r = hypot_d(H, 2);
ld r = hypot_d(2, H);
ld c = H[0] / r;
ld s = H[1] / r;
ld& mt = conformal::model_transition;
@ -423,7 +423,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) {
ret = mobius(ret, vid.skiprope, 2);
if(pmodel == mdJoukowskyInverted) {
ld r2 = sqhypot_d(ret, 2);
ld r2 = sqhypot_d(2, ret);
ret[0] = ret[0] / r2;
ret[1] = -ret[1] / r2;
conformal::apply_orientation(ret[1], ret[0]);
@ -473,7 +473,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) {
H[0] -= .5;
ld phi = atan2(H);
ld r = hypot_d(H, 2);
ld r = hypot_d(2, H);
r = pow(r, 1 - mt);
phi *= (1 - mt);
@ -510,7 +510,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) {
case mdEquidistant: case mdEquiarea: {
ld zlev = find_zlev(H);
ld rad = hypot_d(H, 2);
ld rad = hypot_d(2, H);
if(rad == 0) rad = 1;
ld d = hdist0(H);
ld df, zf;
@ -1062,7 +1062,7 @@ void centerpc(ld aspd) {
hyperpoint H = tC0(cwtV);
if(DIM == 2) H = ypush(-vid.yshift) * sphereflip * H;
if(DIM == 3 && !shmup::on && vid.yshift) H = cpush(2, -vid.yshift) * H;
ld R = zero_d(H, DIM) ? 0 : hdist0(H);
ld R = zero_d(DIM, H) ? 0 : hdist0(H);
if(R < 1e-9) {
// either already centered or direction unknown
/* if(playerfoundL && playerfoundR) {
@ -1247,7 +1247,7 @@ void circle_around_center(ld radius, color_t linecol, color_t fillcol, PPR prio)
if(among(pmodel, mdDisk, mdEquiarea, mdEquidistant, mdFisheye) && !(pmodel == mdDisk && hyperbolic && vid.alpha <= -1) && vid.camera_angle == 0) {
hyperpoint ret;
applymodel(xpush0(radius), ret);
ld r = hypot_d(ret, 2);
ld r = hypot_d(2, ret);
queuecircle(current_display->xcenter, current_display->ycenter, r * current_display->radius, linecol, prio, fillcol);
return;
}
@ -1343,7 +1343,7 @@ void queuestraight(hyperpoint X, int style, color_t lc, color_t fc, PPR p) {
hyperpoint H;
applymodel(X, H);
H *= current_display->radius;
ld mul = hypot(vid.xres, vid.yres) / hypot_d(H, 2);
ld mul = hypot(vid.xres, vid.yres) / hypot_d(2, H);
ld m = style == 1 ? -mul : -1;
queuereset(mdUnchanged, p);
@ -1606,7 +1606,7 @@ bool do_draw(cell *c) {
bool do_draw(cell *c, const transmatrix& T) {
if(DIM == 3) {
if(hyperbolic && T[DIM][DIM] > cosh(sightranges[geometry])) return false;
if(euclid && hypot_d(tC0(T), 3) > sightranges[geometry]) return false;
if(euclid && hypot_d(3, tC0(T)) > sightranges[geometry]) return false;
setdist(c, 7, c);
return true;
}

View File

@ -656,7 +656,7 @@ double scale_at(const transmatrix& T) {
applymodel(tC0(T), h1);
applymodel(T * xpush0(.01), h2);
applymodel(T * ypush(.01) * C0, h3);
return sqrt(hypot_d(h2-h1, 2) * hypot_d(h3-h1, 2) / .0001);
return sqrt(hypot_d(2, h2-h1) * hypot_d(2, h3-h1) / .0001);
}
double linewidthat(const hyperpoint& h) {
@ -960,7 +960,7 @@ void dqi_poly::draw() {
ld c1 = ah1[1], c2 = -ah2[1];
if(c1 < 0) c1 = -c1, c2 = -c2;
hyperpoint h = ah1 * c1 + ah2 * c2;
h /= hypot_d(h, 3);
h /= hypot_d(3, h);
if(h[2] < 0 && abs(h[0]) < sin(vid.twopoint_param)) cpha = 1-cpha, pha = 2;
}
if(cpha == 1) pha = 0;

View File

@ -279,7 +279,7 @@ void gen600() {
for(int i=0; i<120; i++) if(inedge[root][i]) adj0.push_back(i);
using namespace hyperpoint_vec;
for(int i=0; i<6; i++) for(int j=i+1; j<12; j++) if(zero_d(vertices120[adj0[i]] + vertices120[adj0[j]], 3))
for(int i=0; i<6; i++) for(int j=i+1; j<12; j++) if(zero_d(3, vertices120[adj0[i]] + vertices120[adj0[j]]))
swap(adj0[j], adj0[i+6]);
for(int i=0; i<120; i++) for(int j=0; j<120; j++)