X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=mgraph.c;h=46c7533827b1445c2498773106301e2898a94f47;hp=19bb4ba2afbbafaa803e328e7e93d848a1ca1494;hb=fcb05a81ecead2dcd3375c6d4ceb528ca6e181c0;hpb=456ce271eea85ff5acfe6a4416fa6c085d998c64 diff --git a/mgraph.c b/mgraph.c index 19bb4ba..46c7533 100644 --- a/mgraph.c +++ b/mgraph.c @@ -4,35 +4,45 @@ #include "mgraph.h" -static const unsigned dx[V6]= { +1, +1, 0, -1, -1, 0 }, - dy[V6]= { 0, +Y1, +Y1, 0, -Y1, -Y1 }; +static const unsigned dx[2][V6]= {{ +1, 0, -1, -1, -1, 0 }, + { +1, +1, 0, -1, 0, +1 }}, + dy[V6]= { 0, -Y1, -Y1, 0, +Y1, +Y1 }; int edge_end2(unsigned v1, int e) { - /* The topology is equivalent to that of a square lattice with only - * half of the diagonals. Ie, the result of shearing the triangular - * lattice to make the lines of constant x vertical. This gives - * these six directions: - * - * 2 1 - * | / - * |/ - * 3--*--0 - * /| - * / | - * 4 5 - * - * This also handily makes vertical the numbering discontinuity, - * where the join happens. - */ unsigned x, y; - y= (v1 & YMASK) + dy[e]; - if (y & ~YMASK) return -1; + y= (v1 & ~XMASK) + dy[e]; + if (y >= Y*Y1) return -1; - x= (v1 & XMASK) + dx[e]; + x= (v1 & XMASK) + dx[(v1 >> YSHIFT) & 1][e]; if (x & ~XMASK) { + //int orgy= y; y= (Y-1)*Y1 - y; x &= XMASK;; + //printf("%40s %02x -%d-> %02x (was %02x) \n", "", v1, e, x|y, x|orgy); } + return x | y; } + +static const unsigned reverse[2][V6]= {{ 3, 4, 5, 0, 1, 2 }, + { 3, 2, 1, 0, 5, 4 }}; + +int edge_reverse(int v1, int e) { + unsigned x2; + int flip, eprime; + + x2= (v1 & XMASK) + dx[(v1 >> YSHIFT) & 1][e]; + flip= !!(x2 & ~XMASK); + eprime= reverse[flip][e]; +// printf("%60s %02x -%d->,<-%d- (%02x) [x2=%x flip=%d]\n","", +// v1,e,eprime, EDGE_END2(v1,e), x2,flip); + return eprime; +} + +int vertices_span_join_p(int v0, int v1) { + int v0x= v0 & XMASK; + int v1x= v1 & XMASK; + int diff= v0x-v1x; + return diff < -2 || diff > 2; +}