chiark / gitweb /
before abolish oee_edgemap in favour of something weirder
[moebius2.git] / bgl.cpp
diff --git a/bgl.cpp b/bgl.cpp
index ae36ea4abb5d6ecf8a8027a00598aff5048a95c4..e75918a9d6d8b5799e51caedb2ae39072728b7db 100644 (file)
--- a/bgl.cpp
+++ b/bgl.cpp
@@ -28,7 +28,7 @@ extern "C" {
  * e is 0..5.  The edge is edge e out of vertex (x,y).
  *
  * BGL expects an undirected graph's edges to have two descriptors
- * each, one in each direction.
+ * each, one in each direction (otherwise e would be just 0..2).
  */
 
 /*
@@ -50,19 +50,41 @@ class Graph { }; // this is a dummy as our graph has no actual representation
 
 using namespace boost;
 
-struct OutEdgeIterator :
+/*
+ * We use the following alternative numbering for iterating over edges:
+ *
+ *      ix:        \0   /1
+ *                  \  /
+ *               ___ 0   __
+ *               2    1   3
+ *                  /  \
+ *                4/   5\
+ *
+ *
+ * This numbering permits the order-4 nodes at the strip's edge
+ * to have a contiguous edge iterator values 2..5 or 0..3.
+ */
+static const int oee_edgemap[V6]=
+  { 2<<ESHIFT, 1<<ESHIFT, 3<<ESHIFT, 2<<ESHIFT, 4<<ESHIFT, 5<<ESHIFT };
+
+class OutEdgeIterator :
   public iterator_facade<
     OutEdgeIterator,
     int const,
     forward_traversal_tag
 > {
-  int f;
-  void increment() { f += 1<<ESHIFT; }
-  bool equal(OutEdgeIterator const& other) const { return f == other.f; }
+  int v, ix, f;
+  
+  void setf() { f= v | oee_edgemap[ix]; }
+ public:
+  void increment() { ix++; setf(); }
+  bool equal(OutEdgeIterator const& other) const { return ix == other.ix; }
   int const& dereference() const { return f; }
   OutEdgeIterator() { }
-  OutEdgeIterator(int _f) : f(_f) { }
-  OutEdgeIterator(int v, int e) : f(e << ESHIFT | v) { }
+  OutEdgeIterator(int _v, int _ix) : v(_v), ix(_ix) { setf(); }
+
+  static int voe_min(int _v) { return _v & YMASK ? 0 : 2; }
+  static int voe_max(int _v) { return ~_v & YMASK ? V6 : 4; }
 };
  
 typedef counting_iterator<int> VertexIterator;
@@ -103,11 +125,11 @@ namespace boost {
   inline int target(int f, const Graph&) { return EDGE_END2(f&VMASK, f>>ESHIFT); }
   inline std::pair<OutEdgeIterator,OutEdgeIterator>
   out_edges(int v, const Graph&) {
-    return std::make_pair(OutEdgeIterator(v, VE_MIN(v)),
-                         OutEdgeIterator(v, VE_MAX(v)));
+    return std::make_pair(OutEdgeIterator(v, OutEdgeIterator::voe_min(v)),
+                         OutEdgeIterator(v, OutEdgeIterator::voe_max(v)));
   }
   inline unsigned out_degree(int v, const Graph&) {
-    return VE_MAX(v) - VE_MIN(v);
+    return OutEdgeIterator::voe_max(v) - OutEdgeIterator::voe_min(v);
   }
 
   // Concept VertexListGraph: