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