From fc964ec7b221b77c4762f55ad0c2b8e07b74e8b2 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 20 May 2018 15:30:43 +0200 Subject: [PATCH] simplified hyperpoint.cpp a bit --- hyper.h | 28 ++++++++++++++++------------ hyperpoint.cpp | 20 ++++---------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/hyper.h b/hyper.h index 1de1e941..3dc6380e 100644 --- a/hyper.h +++ b/hyper.h @@ -27,10 +27,9 @@ typedef long double ld; #define DEBSM(x) -struct hyperpoint { - ld tab[3]; - ld& operator [] (int i) { return tab[i]; } - const ld& operator [] (int i) const { return tab[i]; } +struct hyperpoint : array { + hyperpoint() {} + hyperpoint(ld x, ld y, ld z) : array {x,y,z} {} }; struct transmatrix { @@ -56,7 +55,7 @@ inline transmatrix operator * (const transmatrix& T, const transmatrix& U) { return R; } -hyperpoint hpxyz(ld x, ld y, ld z); +#define hpxyz hyperpoint namespace hyperpoint_vec { @@ -2256,19 +2255,24 @@ struct qcir { enum eKind { pkPoly, pkLine, pkString, pkCircle, pkShape, pkResetModel, pkSpecial }; +union polyunion { + qpoly poly; + qline line; + qchr chr; + qcir cir; + double dvalue; + polyunion() {} + }; + struct polytodraw { eKind kind; int prio, col; - union { - qpoly poly; - qline line; - qchr chr; - qcir cir; - double dvalue; - } u; + polyunion u; #if CAP_ROGUEVIZ string* info; polytodraw() { info = NULL; } +#else + polytodraw() {} #endif }; diff --git a/hyperpoint.cpp b/hyperpoint.cpp index 4baa5f7d..2aade363 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -118,24 +118,18 @@ ld atan2_auto(ld y, ld x) { // by points in 3D space (Minkowski space) such that x^2+y^2-z^2 == -1, z > 0 // (this is analogous to representing a sphere with points such that x^2+y^2+z^2 == 1) -hyperpoint hpxyz(ld x, ld y, ld z) { - // EUCLIDEAN - hyperpoint r; r[0] = x; r[1] = y; r[2] = z; return r; - } - hyperpoint hpxy(ld x, ld y) { - // EUCLIDEAN return hpxyz(x,y, euclid ? 1 : sphere ? sqrt(1-x*x-y*y) : sqrt(1+x*x+y*y)); } // center of the pseudosphere -const hyperpoint Hypc = { {0,0,0} }; +const hyperpoint Hypc(0,0,0); // origin of the hyperbolic plane -const hyperpoint C0 = { {0,0,1} }; +const hyperpoint C0(0,0,1); // a point (I hope this number needs no comments ;) ) -const hyperpoint Cx1 = { {1,0,1.41421356237} }; +const hyperpoint Cx1(1,0,1.41421356237); // this function returns approximate square of distance between two points // (in the spherical analogy, this would be the distance in the 3D space, @@ -207,13 +201,7 @@ ld hypot_auto(ld x, ld y) { // move H back to the sphere/hyperboloid/plane hyperpoint normalize(hyperpoint H) { - ld Z; - if(sphere) Z = sqrt(intval(H, Hypc)); - else if(!euclid) { - Z = intval(H, Hypc); - Z = sqrt(-Z); - } - else Z = H[2]; + ld Z = zlevel(H); for(int c=0; c<3; c++) H[c] /= Z; return H; }