From: Ian Jackson Date: Tue, 1 Jan 2008 20:24:47 +0000 (+0000) Subject: new topology; check that graph and stuff makes sense X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=commitdiff_plain;h=62f97dcbc53754ef8a81add86946e54825c4c096 new topology; check that graph and stuff makes sense --- diff --git a/bgl.cpp b/bgl.cpp index 28c6ee6..30a1767 100644 --- a/bgl.cpp +++ b/bgl.cpp @@ -99,7 +99,7 @@ class OutEdgeIterator : static int voe_min(int _v) { return (_v & YMASK) ? 2 : 3; } static int voe_max(int _v) { return (~_v & YMASK) ? V6 : 4; } - static int voe_degree(int _v) { return (_v & YMASK | ~_v & YMASK) ? 4 : V6; } + static int voe_degree(int _v) { return RIM_VERTEX_P(_v) ? 4 : V6; } }; typedef counting_iterator VertexIterator; diff --git a/mgraph.c b/mgraph.c index cf57624..23a10e3 100644 --- a/mgraph.c +++ b/mgraph.c @@ -4,19 +4,23 @@ #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) { unsigned x, y; y= (v1 & YMASK) + dy[e]; - if (y & ~YMASK) return -1; + 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; } diff --git a/mgraph.h b/mgraph.h index 0870489..de26852 100644 --- a/mgraph.h +++ b/mgraph.h @@ -4,26 +4,35 @@ /* * Vertices in strip are numbered as follows: * - * ___ X-2 ___ X-1 ___ 0 ___ 1 ___ 2 ___ 3 ___ 4 __ - * Y-1 Y-1 0 0 0 0 0 + * | + * ___ X-2 ___ X-1 ___| 0 ___ 1 ___ 2 ___ 3 ___ 4 __ + * Y-1 Y-1 |0 0 0 0 0 * / \ / \ / \ / \ / \ / \ / \ - * / \ / \ / \ / \ / \ / \ / \ - * X-3 ___ X-2 ___ X-1 ___ 0 ___ 1 ___ 2 ___ 3 ___ 4 - * Y-2 Y-2 Y-2 1 1 1 1 1 - * \ / \ / \ / \ / \ / \ / \ / + * / \ / \ /| \ / \ / \ / \ / \ + * X-3 ___ X-2 ___ X-1|___ 0 ___ 1 ___ 2 ___ 3 ___ 4 + * Y-2 Y-2 Y-2| 1 1 1 1 1 + * \ / \ / \| / \ / \ / \ / \ / * \ / \ / \ / \ / \ / \ / \ / - * ___ X-3 ___ X-2 ___ X-1 ___ 0 ___ 1 ___ 2 ___ 3 __ - * Y-3 Y-3 Y-3 2 2 2 2 - * - * . . . . . . . . . . . . . . . - * - * X-4 ___ X-3 ___ X-2 ___ X-1 ___ 0 ___ 1 ___ 2 ___ 3 - * 1 1 1 1 Y-2 Y-2 Y-2 Y-2 - * \ / \ / \ / \ / \ / \ / \ / - * \ / \ / \ / \ / \ / \ / \ / - * ___ X-4 ___ X-3 ___ X-2 ___ X-1 ___ 0 ___ 1 ___ 2 __ - * 0 0 0 0 Y-1 Y-1 Y-1 - * + * ___ X-2 ___ X-1 ___| 0 ___ 1 ___ 2 ___ 3 __ 4 ___ + * Y-3 Y-3 |2 2 2 2 2 + * / \ / \ / \ / \ / \ / \ / \ + * / \ / \ /| \ / \ / \ / \ / \ + * X-3 ___ X-2 ___ X-1|___ 0 ___ 1 ___ 2 ___ 3 ___ 4 + * Y-4 Y-4 Y-4| 3 3 3 3 3 + * | + * . . . . .| . . . . . . . . . . + * | + * ___ X-2 ___ X-1 ___| 0 ___ 1 ___ 2 ___ 3 ___ 4 ___ + * 2 2 |Y-3 Y-3 Y-3 Y-3 Y-3 + * / \ / \ / \ / \ / \ / \ / \ + * / \ / \ /| \ / \ / \ / \ / \ + * __ X-2 ___ X-1|___ 0 ___ 1 ___ 2 ___ 3 ___ 3 ___ 4 + * 1 1 | Y-2 Y-2 Y-2 Y-2 Y-2 Y-2 + * / \ / \ / \| / \ / \ / \ / \ / + * / \ / \ / \ / \ / \ / \ / \ / + * -3 ___ X-2 ___ X-1 ___| 0 ___ 1 ___ 2 ___ 3 ___ 4 ___ + * 0 0 0 |Y-1 Y-1 Y-1 Y-1 Y-1 + * | * Node x,y for * 0 <= x < X x = distance along * 0 <= y < Y y = distance across @@ -40,12 +49,12 @@ * * We label edges as follows: Or in the square view: * - * \2 /1 2 1 - * \ / | / - * ___ 0 __ |/ - * 3 1 0 3--*--0 - * / \ /| - * 4/ 5\ / | + * \2 /1 2 1 + * \ / | / + * ___ 0 __ |/ + * 3 1 0 3--*--0 + * / \ /| + * 4/ 5\ / | * 4 5 * * (This makes the numbering @@ -58,12 +67,12 @@ #include "common.h" -#define DIMBITS 5 +#define DIMBITS 4 #define XBITS DIMBITS #define X (1<vertex[1][k]= conformation[vb][k]; t->vertex[2][k]= conformation[vc][k]; } + if (!vertex_in_triangles_checked) { + vertex_in_triangles[va]++; + vertex_in_triangles[vb]++; + vertex_in_triangles[vc]++; + } displaylist[ntris++]= t; } static void generate_display_list(void) { - int vb, ve[3], e; + int vb, ve[V6], e; ntris= 0; FOR_VERTEX(vb) { - /* We use the two triangles in the parallelogram vb, vb+e0, vb+e1, vb+e2. + /* We use the two triangles in the parallelogram vb, vb+e5, vb+e0, vb+e1. * We go round each triangle clockwise (although our surface is non- - * orientable so it shouldn't matter). + * orientable so it shouldn't matter). Picking the parallelogram + * to our right avoids getting it wrong at the join. */ - for (e=0; e<3; e++) ve[e]= EDGE_END2(vb,e); - if (ve[1]>=0) { - if (ve[0]>=0) addtriangle(vb,ve[0],ve[1]); - if (ve[2]>=0) addtriangle(vb,ve[1],ve[2]); + for (e=0; e=0); + if (ve[5]>=0) addtriangle(vb,ve[0],ve[5]); + if (ve[1]>=0) addtriangle(vb,ve[1],ve[0]); + } + + if (!vertex_in_triangles_checked) { + int v, expd; + FOR_VERTEX(v) { + expd= RIM_VERTEX_P(v) ? 3 : 6; + if (vertex_in_triangles[v] != expd) { + fprintf(stderr,"vertex %02x used for %d triangles, expected %d\n", + v, vertex_in_triangles[v], expd); + abort(); + } } + vertex_in_triangles_checked= 1; } } @@ -578,6 +598,23 @@ static void check_input(void) { show(); } +static void topocheck(void) { + int v1,e,v2,eprime,v1prime, count; + FOR_EDGE(v1,e,v2) { + count= 0; + FOR_VEDGE(v2,eprime,v1prime) + if (v1prime==v1) count++; + if (count!=1) { + fprintf(stderr,"%02x -%d-> %02x reverse edge count = %d!\n", + v1,e,v2, count); + FOR_VEDGE(v2,eprime,v1prime) + fprintf(stderr,"%02x -%d-> %02x -> %d -> %02x\n", + v1,e,v2,eprime,v1prime); + exit(-1); + } + } +} + int main(int argc, const char *const *argv) { static const int wantedevents= POLLIN|POLLPRI|POLLERR|POLLHUP; @@ -585,6 +622,9 @@ int main(int argc, const char *const *argv) { int k, i, r, *xfds, nxfds, polls_alloc=0; struct pollfd *polls=0; int motion_deferred=0, motion_x=-1, motion_y=-1; + + topocheck(); + if (argc==1) { printf("topology self-consistent, ok\n"); exit(0); } if (argc != 2 || argv[1][0]=='-') { fputs("need filename\n",stderr); exit(8);