From d0e7541b4510f4e1cdf6be515f2b77ef55fba5b3 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Fri, 30 Jul 2021 11:49:13 +0200 Subject: [PATCH] nicer auto sight range computation, and range(...) directive in the tes language --- arbitrile.cpp | 15 ++++++++++----- archimedean.cpp | 5 +---- cell.cpp | 21 +++++++++++++++++++++ geometry.cpp | 1 + 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/arbitrile.cpp b/arbitrile.cpp index 7d93afef..65dcae9b 100644 --- a/arbitrile.cpp +++ b/arbitrile.cpp @@ -79,6 +79,7 @@ struct arbi_tiling { vector sliders; ld cscale; + int range; string filename; geometryinfo1& get_geometry(); @@ -379,6 +380,7 @@ EX void load(const string& fname, bool after_sliding IS(false)) { c.comment = ""; c.filename = fname; c.cscale = 1; + c.range = 0; exp_parser ep; ep.s = s; ld angleunit = 1, distunit = 1, angleofs = 0; @@ -490,6 +492,10 @@ EX void load(const string& fname, bool after_sliding IS(false)) { c.cscale = ep.rparse(); ep.force_eat(")"); } + else if(ep.eat("range(")) { + c.range = ep.iparse(); + ep.force_eat(")"); + } else if(ep.eat("conway(\"")) { string s = ""; while(true) { @@ -790,11 +796,9 @@ struct hrmap_arbi : hrmap { transmatrix T = xpush(.01241) * spin(1.4117) * xpush(0.1241) * Id; arbi_matrix[origin] = make_pair(alt, T); altmap[alt].emplace_back(origin, T); - - cgi.base_distlimit = 0; - celllister cl(origin->c7, 1000, 200, NULL); - ginf[geometry].distlimit[0] = cgi.base_distlimit = cl.dists.back(); - if(sphere) cgi.base_distlimit = SEE_ALL; + + if(!current.range) + current.range = auto_compute_range(origin->c7); } ~hrmap_arbi() { @@ -1143,6 +1147,7 @@ EX void convert() { ac.order++; ac.comment = ac.filename = "converted from: " + full_geometry_name(); ac.cscale = cgi.scalefactor; + ac.range = cgi.base_distlimit; int N = isize(old_shvids); ac.shapes.resize(N); diff --git a/archimedean.cpp b/archimedean.cpp index 4f9fc3ce..336d070b 100644 --- a/archimedean.cpp +++ b/archimedean.cpp @@ -578,10 +578,7 @@ struct hrmap_archimedean : hrmap { origin->move(1)->c.connect(1, origin->move(0), 2*current.N-1, false); } - cgi.base_distlimit = 0; - celllister cl(origin->c7, 1000, 200, NULL); - ginf[geometry].distlimit[!BITRUNCATED] = cgi.base_distlimit = cl.dists.back(); - if(sphere) cgi.base_distlimit = SEE_ALL; + auto_compute_range(origin->c7); } ~hrmap_archimedean() { diff --git a/cell.cpp b/cell.cpp index 866ca7da..b2fbb42b 100644 --- a/cell.cpp +++ b/cell.cpp @@ -1425,6 +1425,27 @@ EX bool is_boundary(cell *c) { return (cgflags & qPORTALSPACE) && isWall(c->wall); } +/** compute the distlimit for a tessellation automatically */ +EX int auto_compute_range(cell *c) { + if(sphere) { + cgi.base_distlimit = SEE_ALL; + return SEE_ALL; + } + cgi.base_distlimit = 0; + const int expected_count = 400; + celllister cl(c, 1000, expected_count, NULL); + int z = isize(cl.dists); + int d = cl.dists.back(); + while(cl.dists[z-1] == d) z--; + if(true) { // if(cgflags & DF_GEOM) { + println(hlog, "last distance = ", cl.dists.back()); + println(hlog, "ball size = ", isize(cl.dists)); + println(hlog, "previous ball size = ", z); + } + if(isize(cl.dists) * z > expected_count * expected_count) d--; + return ginf[geometry].distlimit[0] = cgi.base_distlimit = d; + } + EX cell out_of_bounds; EX heptagon oob; diff --git a/geometry.cpp b/geometry.cpp index 8d5029f3..79654d5d 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -732,6 +732,7 @@ void geometry_information::prepare_basics() { scalefactor = csc; hcrossf = crossf = orbsize = hcrossf7 * csc; hexf = rhexf = hexvdist = csc * .5; + base_distlimit = arb::current.range; } if(is_subcube_based(variation)) {