From 4a908273d0741f577791d7a6d1b134a84d5e14bc Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 27 Mar 2024 21:19:44 +0100 Subject: [PATCH] irregular maps no longer save a different modeline every time due to floating point precision --- irregular.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/irregular.cpp b/irregular.cpp index 8d7d3204..10328d15 100644 --- a/irregular.cpp +++ b/irregular.cpp @@ -804,6 +804,8 @@ bool save_map(const string& fname) { return true; } +vector float_order; + EX void save_map_bin(hstream& f) { if(!base) { f.write(-1); return; } auto& all = base->allcells(); @@ -814,6 +816,19 @@ EX void save_map_bin(hstream& f) { f.write (base_geometry); f.write (isize(all)); f.write (origcells); + int foi = 0; + + auto check_float_order = [&] (ld x) { + if(foi >= isize(float_order)) { + float_order.push_back(x); + f.write(x); + } + else if(abs(float_order[foi] - x) > 1e-6) { + println(hlog, float_order[foi], " vs ", x, " : abs difference is ", abs(float_order[foi] - x)); + float_order[foi] = x; + } + f.write(float_order[foi++]); + }; for(auto h: all) { origcells = 0; @@ -823,9 +838,9 @@ EX void save_map_bin(hstream& f) { f.write (origcells); for(auto i: cells_of_heptagon[h->master]) if(cells[i].generation == 0) { auto &ci = cells[i]; - f.write(ci.p[0]); - f.write(ci.p[1]); - f.write(ci.p[LDIM]); + check_float_order(ci.p[0]); + check_float_order(ci.p[1]); + check_float_order(ci.p[LDIM]); } } } @@ -874,6 +889,7 @@ EX void load_map_bin(hstream& f) { density = cellcount * 1. / isize(all); cells.clear(); + float_order.clear(); for(auto h: all) { int q = f.get(); @@ -886,6 +902,9 @@ EX void load_map_bin(hstream& f) { a = f.get(); b = f.get(); c = f.get(); + float_order.push_back(a); + float_order.push_back(b); + float_order.push_back(c); s.p = hpxyz(a, b, c); s.p = normalize(s.p); for(auto c0: all) s.relmatrices[c0] = calc_relative_matrix(c0, h, s.p);