chiark / gitweb /
rename project to view; do not clean best
[moebius2.git] / mgraph.c
1 /*
2  * Graph topology
3  */
4
5 #include "mgraph.h"
6
7 static const unsigned dx[V6]= {  +1,  +1,   0,  -1,  -1,   0  },
8                       dy[V6]= {   0, -Y1, -Y1,   0, +Y1, +Y1  };
9
10 int edge_end2(unsigned v1, int e) {
11   /* The topology is equivalent to that of a square lattice with only
12    * half of the diagonals.  Ie, the result of shearing the triangular
13    * lattice to make the lines of constant x vertical.  This gives
14    * these six directions:
15    *
16    *                2  1
17    *                | /
18    *                |/
19    *             3--*--0
20    *               /|
21    *              / |
22    *             4  5
23    *
24    * This also handily makes vertical the numbering discontinuity,
25    * where the join happens.
26    */
27   unsigned x, y;
28
29   y= (v1 & YMASK) + dy[e];
30   if (y & ~YMASK) return -1;
31
32   x= (v1 & XMASK) + dx[e];
33   if (x & ~XMASK) {
34     y= (Y-1)*Y1 - y;
35     x &= XMASK;;
36   }
37   return x | y;
38 }