From df9c01f276df2083d71b3508924c8f3c6ad7d02c Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 14 Aug 2019 18:59:21 +0200 Subject: [PATCH] models:: Collignon projection --- config.cpp | 3 +++ drawing.cpp | 17 ++++++++++++----- hypgraph.cpp | 26 ++++++++++---------------- models.cpp | 12 ++++++++++++ 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/config.cpp b/config.cpp index 83334070..b504512b 100644 --- a/config.cpp +++ b/config.cpp @@ -439,6 +439,8 @@ EX void initConfig() { addsaver(vid.twopoint_param, "twopoint parameter", 1); addsaver(vid.stretch, "stretch", 1); addsaver(vid.binary_width, "binary-tiling-width", 1); + addsaver(vid.collignon_parameter, "collignon-parameter", 1); + addsaver(vid.collignon_reflected, "collignon-reflect", false); addsaver(vid.creature_scale, "3d-creaturescale", 1); addsaver(vid.height_width, "3d-heightwidth", 1.5); @@ -2382,6 +2384,7 @@ EX unordered_map params = { {"fade", shot::fade}, {"mgrid", vid.multiplier_grid}, {"mring", vid.multiplier_ring}, + {"collignon", vid.collignon_parameter}, #endif }; diff --git a/drawing.cpp b/drawing.cpp index d5310efd..867dbbc6 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -686,6 +686,11 @@ int mercator_coord; int mercator_loop_min = 0, mercator_loop_max = 0; ld mercator_period; +auto pzero(ld t) { + if(abs(t) < 1e-6) return 2 * current_display->radius; + return t; + } + ld period_at(ld y) { ld m = current_display->radius; @@ -695,12 +700,14 @@ ld period_at(ld y) { case mdBand: return m * 4; case mdSinusoidal: - return m * 2 * cos(y * M_PI); + return pzero(m * 2 * cos(y * M_PI)); case mdMollweide: - return (abs(y) > .5-1e-6) ? m * 2 : m * 2 * sqrt(1 - y*y*4); - case mdCollignon: -// return (y < -.499999) ? m*2 : m*(1+2*y); - return (abs(y) < 1e-6) ? m*2 : m*2*y; // y = signed_sqrt(sin_auto(y) + whatever[0]); + return pzero(m * 2 * sqrt(1 - y*y*4)); + case mdCollignon: { + if(vid.collignon_reflected && y > 0) y = -y; + y += signed_sqrt(vid.collignon_parameter); + return pzero(abs(m*y*2/1.2)); + } default: return m * 2; } diff --git a/hypgraph.cpp b/hypgraph.cpp index 2f852dba..779fed37 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -310,6 +310,8 @@ hyperpoint compute_hybrid(hyperpoint H, int rootid) { return ret; } +EX ld signed_sqrt(ld x) { return x > 0 ? sqrt(x) : -sqrt(-x); }; + EX void applymodel(hyperpoint H, hyperpoint& ret) { hyperpoint H_orig = H; @@ -682,23 +684,15 @@ EX void applymodel(hyperpoint H, hyperpoint& ret) { break; case mdCollignon: - find_zlev(H); /* does not look nicely otherwise */ - if(hyperbolic) H = ypush(-1) * H; + find_zlev(H); makeband(H, ret, [] (ld& x, ld& y) { - auto signed_sqrt = [] (ld x) { return x > 0 ? sqrt(x) : -sqrt(-x); }; -/* - if(sphere) { - y = M_PI / 2 - y; - x = sin_auto(y/2) * x; - y = (sin_auto(y/2) - .5) * M_PI; - } - if(hyperbolic) { - ld mul = signed_sqrt(sinh(y) + 1); - x *= mul; - y = mul + signed_sqrt(sinh(1) + 1); - }*/ - y = signed_sqrt(sin_auto(y) + whatever[0]); - x *= y; + ld sgn = 1; + if(vid.collignon_reflected && y > 0) y = -y, sgn = -1; + y = signed_sqrt(sin_auto(y) + vid.collignon_parameter); + x *= y / 1.2; + y -= signed_sqrt(vid.collignon_parameter); + y *= sgn; + y *= M_PI; }); break; diff --git a/models.cpp b/models.cpp index 3c550677..6f988cdc 100644 --- a/models.cpp +++ b/models.cpp @@ -554,6 +554,18 @@ EX namespace models { }); } + if(pmodel == mdCollignon) { + dialog::addSelItem(XLAT("parameter"), fts(vid.collignon_parameter) + (vid.collignon_reflected ? " (r)" : ""), 'b'); + dialog::add_action([](){ + dialog::editNumber(vid.collignon_parameter, -1, 1, .1, 1, XLAT("parameter"), + "" + ); + dialog::extra_options = [] { + dialog::addBoolItem_action(XLAT("reflect"), vid.collignon_reflected, 'R'); + }; + }); + } + if(pmodel == mdSpiral && !euclid) { dialog::addSelItem(XLAT("spiral angle"), fts(spiral_angle) + "°", 'x'); dialog::add_action([](){