diff --git a/cell.cpp b/cell.cpp index d67c7bcf..163883ee 100644 --- a/cell.cpp +++ b/cell.cpp @@ -441,11 +441,8 @@ EX int compdist(int dx[]) { EX int celldist(cell *c) { if(experimental) return 0; - if(hybri) { - auto w = hybrid::get_where(c); - if(sl2) w.second = 0; - return PIU ( celldist(w.first) + abs(w.second) ); - } + if(hybri) + return hybrid::celldistance(c, currentmap->gamestart()); if(nil && !quotient) return DISTANCE_UNKNOWN; if(euclid) return celldistance(currentmap->gamestart(), c); if(sphere || binarytiling || WDIM == 3 || cryst || solnih || penrose) return celldistance(currentmap->gamestart(), c); @@ -983,10 +980,7 @@ EX cell *random_in_distance(cell *c, int d) { EX int celldistance(cell *c1, cell *c2) { - if(prod) { - auto w1 = hybrid::get_where(c1), w2 = hybrid::get_where(c2); - return PIU ( celldistance(w1.first, w2.first) + abs(w1.second - w2.second) ); - } + if(hybri) return hybrid::celldistance(c1, c2); #if CAP_FIELD if(geometry == gFieldQuotient && !GOLDBERG) diff --git a/nonisotropic.cpp b/nonisotropic.cpp index 7500c3e2..18b85c2c 100644 --- a/nonisotropic.cpp +++ b/nonisotropic.cpp @@ -1238,6 +1238,29 @@ EX namespace hybrid { } } + EX int celldistance(cell *c1, cell *c2) { + if(cgi.steps == 0) { + auto w1 = hybrid::get_where(c1), w2 = hybrid::get_where(c2); + return PIU (hr::celldistance(w1.first, w2.first)) + abs(w1.second - w2.second); + } + else { + int s = 0; + int a = 999999, b = -999999; + auto c = c1; + do { + auto w1 = hybrid::get_where(c), w2 = hybrid::get_where(c2); + if(w1.second == w2.second) { + int d = PIU(hr::celldistance(w1.first, w2.first)); + a = min(s+d, a); + b = max(s-d, a); + } + c = c->cmove(c1->type-1); s++; + } + while(c != c1); + return min(a, s-b); + } + } + EX } EX namespace product {