X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=view.c;fp=view.c;h=cfa39753f1e89d29329ce115d1328c98c9914f57;hp=72ea2372f81c90d66e372e583d9fb83925e9ae78;hb=62f97dcbc53754ef8a81add86946e54825c4c096;hpb=d9aa142b98fffa94e33f47056090d42f8d6afae3 diff --git a/view.c b/view.c index 72ea237..cfa3975 100644 --- a/view.c +++ b/view.c @@ -54,6 +54,8 @@ static void transform_coordinates(void) { } } +static int vertex_in_triangles[N], vertex_in_triangles_checked; + static void addtriangle(int va, int vb, int vc) { Triangle *t= &trisbuffer[ntris]; int k; @@ -64,23 +66,41 @@ static void addtriangle(int va, int vb, int vc) { t->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);