From b898365d6875c19ca99a77ab0acaed863cb2c929 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 31 Jul 2019 12:19:39 +0200 Subject: [PATCH] solv:: lazy version of inv_exp --- hyper.h | 2 +- hypgraph.cpp | 2 +- sol.cpp | 21 +++++++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/hyper.h b/hyper.h index 234f9eb2..fdc8236b 100644 --- a/hyper.h +++ b/hyper.h @@ -5631,7 +5631,7 @@ namespace kite { namespace solv { extern transmatrix local_perspective; hrmap *new_map(); - hyperpoint inverse_exp(hyperpoint h); + hyperpoint inverse_exp(hyperpoint h, bool lazy); transmatrix get_solmul(const transmatrix T, const transmatrix V); extern string solshader; diff --git a/hypgraph.cpp b/hypgraph.cpp index b2e7e3a9..142604b0 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -320,7 +320,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { } case mdSolPerspective: { - auto S = solv::inverse_exp(H); + auto S = solv::inverse_exp(H, false); ld ratio = vid.xres / current_display->tanfov / current_display->radius / 2; ret[0] = S[0]/S[2] * ratio; ret[1] = S[1]/S[2] * ratio; diff --git a/sol.cpp b/sol.cpp index a775b941..562ea97a 100644 --- a/sol.cpp +++ b/sol.cpp @@ -111,21 +111,26 @@ namespace solv { return 0.5 - atan((0.5-x) / y) / M_PI; } - - pt inverse_exp(pt h) { + + pt inverse_exp(pt h, bool lazy) { load_table(); - ld ix = h[0] >= 0. ? x_to_ix(h[0]) : -x_to_ix(-h[0]); - ld iy = h[1] >= 0. ? x_to_ix(h[1]) : -x_to_ix(-h[1]); + ld ix = h[0] >= 0. ? x_to_ix(h[0]) : x_to_ix(-h[0]); + ld iy = h[1] >= 0. ? x_to_ix(h[1]) : x_to_ix(-h[1]); ld iz = tanh(h[2]); - if(ix < 0.) ix = -ix; - if(iy < 0.) iy = -iy; - if(iz < 0.) { iz = -iz; ld s = ix; ix = iy; iy = s; } + if(h[2] < 0.) { iz = -iz; swap(ix, iy); } ix *= PRECX-1; iy *= PRECY-1; iz *= PRECZ-1; + + if(lazy) { + auto r = inverse_exp_table[(iz*PRECY+iy)*PRECX+ix]; + hyperpoint res = C0; + for(int i=0; i<3; i++) res[i] = r[i]; + return res; + } if(ix >= PRECX-1) ix = PRECX-2; if(iy >= PRECX-1) iy = PRECX-2; @@ -135,7 +140,7 @@ namespace solv { int ay = iy, by = ay+1; int az = iz, bz = az+1; - pt res; + pt res = C0; #define S0(x,y,z) inverse_exp_table[(z*PRECY+y)*PRECX+x][t] #define S1(x,y) (S0(x,y,az) * (bz-iz) + S0(x,y,bz) * (iz-az))