MXDIM, and some extra comments

This commit is contained in:
Zeno Rogue 2020-11-01 17:37:51 +01:00
parent 50474abae1
commit 96d28d173a
8 changed files with 67 additions and 43 deletions

View File

@ -841,8 +841,8 @@ void connectHeptagons(heptspin hi, heptspin hs) {
/** T and X are supposed to be equal -- move T so that it is closer to X */
void fixup_matrix(transmatrix& T, const transmatrix& X, ld step) {
for(int i=0; i<MDIM; i++)
for(int j=0; j<MDIM; j++)
for(int i=0; i<MXDIM; i++)
for(int j=0; j<MXDIM; j++)
T[i][j] = (T[i][j] * (1-step) + X[i][j] * step);
/*

View File

@ -12,14 +12,14 @@ shiftmatrix &ggmatrix(cell *c);
EX void fixelliptic(transmatrix& at) {
if(elliptic && at[LDIM][LDIM] < 0) {
for(int i=0; i<MDIM; i++) for(int j=0; j<MDIM; j++)
for(int i=0; i<MXDIM; i++) for(int j=0; j<MXDIM; j++)
at[i][j] = -at[i][j];
}
}
EX void fixelliptic(hyperpoint& h) {
if(elliptic && h[LDIM] < 0)
for(int i=0; i<MDIM; i++) h[i] = -h[i];
for(int i=0; i<MXDIM; i++) h[i] = -h[i];
}
/** find relative_matrix via recursing the tree structure */

11
hyper.h
View File

@ -383,16 +383,23 @@ struct videopar {
extern videopar vid;
/** \brief How many dimensional is the gameplay. In the FPP mode of a 2D geometry, WDIM is 2 */
#define WDIM cginf.g.gameplay_dimension
/** \brief How many dimensional is the graphical representation. In the FPP mode of a 2D geometry, MDIM is 3 */
#define GDIM cginf.g.graphical_dimension
/** \brief How many dimensions of the matrix representation are used. It is usually 3 in 2D geometries (not FPP) and in product geometries, 4 in 3D geometries */
#define MDIM (MAXMDIM == 3 ? 3 : cginf.g.homogeneous_dimension)
/** \brief What dimension of matrices is used in loops (the 'extra' dimensions have values 0 or 1 as in Id)
* Even if MDIM==3, it may be faster to keep 4x4 matrices and perform computations using them (rather than having another condition due to the variable loop size).
* The experiments on my computer show it to be the case, but the effect is not significant, and it may be different on another computer.
*/
#define MXDIM (CAP_MDIM_FIXED ? MAXMDIM : MDIM)
/** \brief The 'homogeneous' dimension index */
#define LDIM (MDIM-1)
#define cclass g.kind
#define self (*this)
// #define MODFIXER (2*10090080*17)
#define BUGCOLORS 3
#define big_unlock (inv::on && !chaosmode)

View File

@ -59,22 +59,22 @@ struct hyperpoint : array<ld, MAXMDIM> {
#endif
inline hyperpoint& operator *= (ld d) {
for(int i=0; i<MDIM; i++) self[i] *= d;
for(int i=0; i<MXDIM; i++) self[i] *= d;
return self;
}
inline hyperpoint& operator /= (ld d) {
for(int i=0; i<MDIM; i++) self[i] /= d;
for(int i=0; i<MXDIM; i++) self[i] /= d;
return self;
}
inline hyperpoint& operator += (const hyperpoint h2) {
for(int i=0; i<MDIM; i++) self[i] += h2[i];
for(int i=0; i<MXDIM; i++) self[i] += h2[i];
return self;
}
inline hyperpoint& operator -= (const hyperpoint h2) {
for(int i=0; i<MDIM; i++) self[i] -= h2[i];
for(int i=0; i<MXDIM; i++) self[i] -= h2[i];
return self;
}
@ -99,7 +99,7 @@ struct hyperpoint : array<ld, MAXMDIM> {
// inner product
inline friend ld operator | (hyperpoint h1, hyperpoint h2) {
ld sum = 0;
for(int i=0; i<MDIM; i++) sum += h1[i] * h2[i];
for(int i=0; i<MXDIM; i++) sum += h1[i] * h2[i];
return sum;
}
};
@ -118,18 +118,18 @@ struct transmatrix {
inline friend hyperpoint operator * (const transmatrix& T, const hyperpoint& H) {
hyperpoint z;
for(int i=0; i<MDIM; i++) {
for(int i=0; i<MXDIM; i++) {
z[i] = 0;
for(int j=0; j<MDIM; j++) z[i] += T[i][j] * H[j];
for(int j=0; j<MXDIM; j++) z[i] += T[i][j] * H[j];
}
return z;
}
inline friend transmatrix operator * (const transmatrix& T, const transmatrix& U) {
transmatrix R;
for(int i=0; i<MDIM; i++) for(int j=0; j<MDIM; j++) {
for(int i=0; i<MXDIM; i++) for(int j=0; j<MXDIM; j++) {
R[i][j] = 0;
for(int k=0; k<MDIM; k++)
for(int k=0; k<MXDIM; k++)
R[i][j] += T[i][k] * U[k][j];
}
return R;
@ -490,14 +490,14 @@ EX ld hypot_auto(ld x, ld y) {
EX hyperpoint normalize(hyperpoint H) {
if(prod) return H;
ld Z = zlevel(H);
for(int c=0; c<MDIM; c++) H[c] /= Z;
for(int c=0; c<MXDIM; c++) H[c] /= Z;
return H;
}
/** like normalize but makes (ultra)ideal points material */
EX hyperpoint ultra_normalize(hyperpoint H) {
if(material(H) <= 0) {
H[MDIM-1] = hypot_d(MDIM-1, H) + 1e-6;
H[LDIM] = hypot_d(LDIM, H) + 1e-6;
}
return normalize(H);
}
@ -531,7 +531,7 @@ EX hyperpoint midz(const hyperpoint& H1, const hyperpoint& H2) {
ld Z = 2;
if(!euclid) Z = zlevel(H3) * 2 / (zlevel(H1) + zlevel(H2));
for(int c=0; c<MDIM; c++) H3[c] /= Z;
for(int c=0; c<MXDIM; c++) H3[c] /= Z;
return H3;
}
@ -611,8 +611,8 @@ EX transmatrix cpush(int cid, ld alpha) {
EX transmatrix xpush(ld alpha) { return cpush(0, alpha); }
EX bool eqmatrix(transmatrix A, transmatrix B, ld eps IS(.01)) {
for(int i=0; i<MDIM; i++)
for(int j=0; j<MDIM; j++)
for(int i=0; i<MXDIM; i++)
for(int j=0; j<MXDIM; j++)
if(std::abs(A[i][j] - B[i][j]) > eps)
return false;
return true;
@ -702,7 +702,7 @@ EX transmatrix parabolic13(ld u, ld v) {
}
EX hyperpoint parabolic10(hyperpoint h) {
if(euclid) { h[MDIM] = 1; return h; }
if(euclid) { h[LDIM] = 1; return h; }
else if(MDIM == 4) return hyperpoint(sinh(h[0]), h[1]/exp(h[0]), h[2]/exp(h[0]), cosh(h[0]));
else return hyperpoint(sinh(h[0]), h[1]/exp(h[0]), cosh(h[0]), 0);
}
@ -768,18 +768,19 @@ EX transmatrix pushxto0(const hyperpoint& H) {
/** set the i-th column of T to H */
EX void set_column(transmatrix& T, int i, const hyperpoint& H) {
for(int j=0; j<MDIM; j++)
for(int j=0; j<MXDIM; j++)
T[j][i] = H[j];
}
/** build a matrix using the given vectors as columns */
EX transmatrix build_matrix(hyperpoint h1, hyperpoint h2, hyperpoint h3, hyperpoint h4) {
transmatrix T;
for(int i=0; i<MDIM; i++)
for(int i=0; i<MXDIM; i++) {
T[i][0] = h1[i],
T[i][1] = h2[i],
T[i][2] = h3[i];
if(MAXMDIM == 4) for(int i=0; i<MDIM; i++) T[i][3] = h4[i];
if(MAXMDIM == 4) T[i][3] = h4[i];
}
return T;
}
@ -868,11 +869,11 @@ EX void fixmatrix_euclid(transmatrix& T) {
EX void orthonormalize(transmatrix& T) {
for(int x=0; x<MDIM; x++) for(int y=0; y<=x; y++) {
ld dp = 0;
for(int z=0; z<MDIM; z++) dp += T[z][x] * T[z][y] * sig(z);
for(int z=0; z<MXDIM; z++) dp += T[z][x] * T[z][y] * sig(z);
if(y == x) dp = 1 - sqrt(sig(x)/dp);
for(int z=0; z<MDIM; z++) T[z][x] -= dp * T[z][y];
for(int z=0; z<MXDIM; z++) T[z][x] -= dp * T[z][y];
}
}
@ -986,7 +987,7 @@ EX transmatrix ortho_inverse(transmatrix T) {
/** \brief inverse of an orthogonal matrix in Minkowski space */
EX transmatrix pseudo_ortho_inverse(transmatrix T) {
for(int i=1; i<MDIM; i++)
for(int i=1; i<MXDIM; i++)
for(int j=0; j<i; j++)
swap(T[i][j], T[j][i]);
for(int i=0; i<MDIM-1; i++)
@ -1127,7 +1128,7 @@ EX hyperpoint mscale(const hyperpoint& t, double fac) {
if(GDIM == 3 && !prod) return cpush(2, fac) * t;
if(prod) fac = exp(fac);
hyperpoint res;
for(int i=0; i<MDIM; i++)
for(int i=0; i<MXDIM; i++)
res[i] = t[i] * fac;
return res;
}
@ -1143,8 +1144,12 @@ EX transmatrix mscale(const transmatrix& t, double fac) {
}
if(prod) fac = exp(fac);
transmatrix res;
for(int i=0; i<MDIM; i++) for(int j=0; j<MDIM; j++)
res[i][j] = t[i][j] * fac;
for(int i=0; i<MXDIM; i++) {
for(int j=0; j<MDIM; j++)
res[i][j] = t[i][j] * fac;
for(int j=MDIM; j<MXDIM; j++)
res[i][j] = t[i][j];
}
return res;
}
@ -1154,17 +1159,25 @@ EX shiftmatrix mscale(const shiftmatrix& t, double fac) {
EX transmatrix xyscale(const transmatrix& t, double fac) {
transmatrix res;
for(int i=0; i<MDIM; i++) for(int j=0; j<GDIM; j++)
res[i][j] = t[i][j] * fac;
for(int i=0; i<MXDIM; i++) {
for(int j=0; j<GDIM; j++)
res[i][j] = t[i][j] * fac;
for(int j=GDIM; j<MXDIM; j++)
res[i][j] = t[i][j];
}
return res;
}
EX transmatrix xyzscale(const transmatrix& t, double fac, double facz) {
transmatrix res;
for(int i=0; i<MDIM; i++) for(int j=0; j<GDIM; j++)
res[i][j] = t[i][j] * fac;
for(int i=0; i<MDIM; i++)
res[i][LDIM] = t[i][LDIM] * facz;
for(int i=0; i<MXDIM; i++) {
for(int j=0; j<GDIM; j++)
res[i][j] = t[i][j] * fac;
res[i][LDIM] =
t[i][LDIM] * facz;
for(int j=LDIM+1; j<MXDIM; j++)
res[i][j] = t[i][j];
}
return res;
}
@ -1181,7 +1194,7 @@ EX transmatrix mzscale(const transmatrix& t, double fac) {
transmatrix res = t * inverse(tcentered) * ypush(-fac) * tcentered;
fac *= .2;
fac += 1;
for(int i=0; i<MDIM; i++) for(int j=0; j<MDIM; j++)
for(int i=0; i<MXDIM; i++) for(int j=0; j<MXDIM; j++)
res[i][j] = res[i][j] * fac;
return res;
}
@ -1300,8 +1313,8 @@ EX ld ortho_error(transmatrix T) {
EX transmatrix transpose(transmatrix T) {
transmatrix result;
for(int i=0; i<MDIM; i++)
for(int j=0; j<MDIM; j++)
for(int i=0; i<MXDIM; i++)
for(int j=0; j<MXDIM; j++)
result[j][i] = T[i][j];
return result;
}
@ -1340,7 +1353,7 @@ inline hyperpoint zpush0(ld x) { return cpush0(2, x); }
/** T * C0, optimized */
inline hyperpoint tC0(const transmatrix &T) {
hyperpoint z;
for(int i=0; i<MDIM; i++) z[i] = T[i][LDIM];
for(int i=0; i<MXDIM; i++) z[i] = T[i][LDIM];
return z;
}

View File

@ -755,7 +755,7 @@ EX transmatrix track_matrix(int at, int dir) {
transmatrix res = unshift(ggmatrix(racing::track[at]));
while(true) {
if(at+dir < 0 || at+dir >= isize(racing::track)) return res;
for(int x=0; x<MDIM; x++) for(int y=0; y<MDIM; y++)
for(int x=0; x<MXDIM; x++) for(int y=0; y<MXDIM; y++)
if(abs(res[y][x]) > 10000) return res;
cell *cur = racing::track[at];
at += dir;

View File

@ -631,7 +631,7 @@ bool force(rugpoint& m1, rugpoint& m2, double rd, bool is_anticusp=false, double
transmatrix iT = rgpushxto0(m1.native);
for(int i=0; i<MDIM; i++) if(std::isnan(m1.native[i])) {
for(int i=0; i<MXDIM; i++) if(std::isnan(m1.native[i])) {
addMessage("Failed!");
println(hlog, "m1 = ", m1.native);
throw rug_exception();

View File

@ -612,7 +612,7 @@ EX void glapplymatrix(const transmatrix& V) {
GLfloat mat[16];
int id = 0;
if(MDIM == 3) {
if(MXDIM == 3) {
for(int y=0; y<3; y++) {
for(int x=0; x<3; x++) mat[id++] = V[x][y];
mat[id++] = 0;

View File

@ -185,6 +185,10 @@
#define MAXMDIM 4
#endif
#ifndef CAP_MDIM_FIXED
#define CAP_MDIM_FIXED 0
#endif
#ifndef CAP_TEXTURE
#define CAP_TEXTURE (CAP_GL && (CAP_PNG || CAP_SDL_IMG) && !ISMINI)
#endif