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