From a6094f7b0cab8b2fd07aad3d0e2f3827d5bf6798 Mon Sep 17 00:00:00 2001 From: ? Date: Tue, 26 Feb 2019 13:08:05 +0100 Subject: [PATCH] 3d:: binary:: celldistance [untested] --- binary-tiling.cpp | 26 ++++++++++++++++++++++---- cell.cpp | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/binary-tiling.cpp b/binary-tiling.cpp index c5576f98..48c8f97d 100644 --- a/binary-tiling.cpp +++ b/binary-tiling.cpp @@ -343,12 +343,30 @@ auto bt_config = addHook(hooks_args, 0, [] () { }); #endif -int celldistance3(cell *c1, cell *c2) { +int celldistance3(cell *c1, cell *c2) { // [untested] int steps = 0; + int d1 = celldistAlt(c1); + int d2 = celldistAlt(c2); + while(d1 > d2) c1 = c1->cmove(8), steps++, d1--; + while(d2 > d1) c2 = c2->cmove(8), steps++, d2--; + vector dx, dy; while(c1 != c2) { - int d1 = celldistAlt(c1), d2 = celldistAlt(c2); - if(d1 >= d2) c1 = c1->cmove(8), steps++; - if(d2 >= d1) c2 = c2->cmove(8), steps++; + dx.push_back((c1->c.spin(8) & 1) - (c2->c.spin(8) & 1)); + dy.push_back((c1->c.spin(8) >> 1) - (c2->c.spin(8) >> 1)); + c1 = c1->cmove(8); + c2 = c2->cmove(8); + steps += 2; + } + int xsteps = steps, sx = 0, sy = 0; + while(isize(dx)) { + xsteps -= 2; + sx *= 2; + sy *= 2; + sx += dx.back(); sy += dy.back(); + dx.pop_back(); dy.pop_back(); + int ysteps = xsteps + abs(sx) + abs(sy); + if(ysteps < steps) steps = ysteps; + if(sx >= 8 || sx <= -8 || sy >= 8 || sy <= -8) break; } return steps; } diff --git a/cell.cpp b/cell.cpp index ddabde12..6d36f6cd 100644 --- a/cell.cpp +++ b/cell.cpp @@ -805,7 +805,7 @@ int heptdistance(cell *c1, cell *c2) { #if CAP_CRYSTAL if(geometry == gCrystal) return crystal::space_distance(c1, c2); #endif - if(!hyperbolic || quotient) return celldistance(c1, c2); + if(!hyperbolic || quotient || DIM == 3) return celldistance(c1, c2); else return heptdistance(c1->master, c2->master); }