chiark / gitweb /
found stuff, before some rearrangement of edge iterator
[moebius2.git] / mgraph.c
diff --git a/mgraph.c b/mgraph.c
new file mode 100644 (file)
index 0000000..3233890
--- /dev/null
+++ b/mgraph.c
@@ -0,0 +1,35 @@
+#include "mgraph.h"
+
+static const unsigned dx[V6]= {   0,  +1,  -1,  +1,  -1,   0  },
+                      dy[V6]= { +Y1, +Y1,   0,   0, -Y1, -Y1  };
+
+
+int edge_end2(unsigned v1, int e) {
+  /* The topology is equivalent to that of a square lattice with only
+   * half of the diagonals.  Ie, the result of shearing the triangular
+   * lattice to make the lines of constant x vertical.  This gives
+   * these six directions:
+   *
+   *                0  1
+   *                | /
+   *                |/
+   *             2--*--3
+   *              /|
+   *             / |
+   *            4  5
+   *
+   * This also handily makes vertical the numbering discontinuity,
+   * where the join happens.
+   */
+  unsigned x, y;
+
+  y= (v1 & YMASK) + dy[e];
+  if (y & ~YMASK) return -1;
+
+  x= (v1 & XMASK) + dx[e];
+  if (x & ~XMASK) {
+    y= (Y-1)*Y1 - y;
+    x &= XMASK;;
+  }
+  return x | y;
+}