chiark / gitweb /
tidyings, more points.
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Mon, 31 Dec 2007 15:52:53 +0000 (15:52 +0000)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Mon, 31 Dec 2007 15:52:53 +0000 (15:52 +0000)
Makefile
energy.c
mgraph.c
mgraph.h
primer.c

index 39d43e33335776d784072e59c2454239122e5099..bec227e7bc409c626b7e59e67c0e0543e81da43b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,12 @@
 
 TARGETS= minimise primer initial view
 
-CWARNS=        -Wall -Wwrite-strings -Wpointer-arith -Werror
+CWARNS=        -Wall -Wwrite-strings -Wpointer-arith -Werror -Wshadow
+CXXWARNS= $(CWARNS) -Wno-shadow
 
 OPTIMISE=      -O2
-CFLAGS=                $(CWARNS) -MMD $(OPTIMISE) -g
-CXXFLAGS=      $(CWARNS) -MMD $(OPTIMISE) -g
+CFLAGS=                -MMD $(OPTIMISE) -g $(CWARNS)
+CXXFLAGS=      -MMD $(OPTIMISE) -g $(CXXWARNS)
 
 LIBGSL= -lgsl -lgslcblas
 
index ce78a54ebed9fc43c27dda82a6a27f0327463f40..d673c14ea2820fd7e8e59b45678f486a842572a0 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -18,8 +18,8 @@ static double noncircular_rim_cost(const Vertices vertices);
 static void compute_vertex_areas(const Vertices vertices, double areas[N]);
 static double best_energy= DBL_MAX;
 
-static void cost(double *energy, double tweight, double tcost);
-#define COST(weight, compute) cost(&energy, (weight), (compute))
+static void addcost(double *energy, double tweight, double tcost);
+#define COST(weight, compute) addcost(&energy, (weight), (compute))
 
 /*---------- main energy computation and subroutines ----------*/
 
@@ -54,7 +54,7 @@ static double compute_energy(const Vertices vertices) {
   return energy;
 }    
 
-static void cost(double *energy, double tweight, double tcost) {
+static void addcost(double *energy, double tweight, double tcost) {
   double tenergy= tweight * tcost;
   printf(" %# e > %# e |", tcost, tenergy);
   *energy += tenergy;
index c66ef489230b9d245453d6930359b0e37669d55d..cf57624262ae1c00224f6566cc112a81e6f50fb6 100644 (file)
--- a/mgraph.c
+++ b/mgraph.c
@@ -8,22 +8,6 @@ static const unsigned dx[V6]= {  +1,  +1,   0,  -1,  -1,   0  },
                       dy[V6]= {   0, -Y1, -Y1,   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:
-   *
-   *                2  1
-   *                | /
-   *                |/
-   *             3--*--0
-   *              /|
-   *             / |
-   *            4  5
-   *
-   * This also handily makes vertical the numbering discontinuity,
-   * where the join happens.
-   */
   unsigned x, y;
 
   y= (v1 & YMASK) + dy[e];
index acbe5c4b277b39a2c8b92aff3957c1978aae7f26..08704894f7ab41841f11f44937a981f26c588a75 100644 (file)
--- a/mgraph.h
+++ b/mgraph.h
@@ -4,16 +4,16 @@
 /*
  * Vertices in strip are numbered as follows:
  *
- *     ___ X-2 ___ X-1 ___ 0   ___ 1   ___ 2   ___ 3   ___ 4   __
- *         Y-1     Y-1      0       0       0       0       0
+ *     ___ X-2 ___ X-1 ___  0  ___  1  ___  2  ___  3  ___  4  __
+ *         Y-1     Y-1     0       0       0       0       0 
  *        /  \    /  \    /  \    /  \    /  \    /  \    /  \
  *       /    \  /    \  /    \  /    \  /    \  /    \  /    \
- *     X-3 ___ X-2 ___ X-1 ___ 0   ___ 1   ___ 2   ___  3  ___ 4
- *     Y-2     Y-2     Y-2      1       1       1       1       1
+ *     X-3 ___ X-2 ___ X-1 ___  0  ___  1  ___  2  ___  3  ___  4
+ *     Y-2     Y-2     Y-2     1       1       1       1       1
  *       \    /  \    /  \    /  \    /  \    /  \    /  \    /
  *        \  /    \  /    \  /    \  /    \  /    \  /    \  /
- *     ___ X-3 ___ X-2 ___ X-1 ___ 0   ___ 1   ___ 2   ___ 3   __
- *         Y-3     Y-3     Y-3      2       2       2       2
+ *     ___ X-3 ___ X-2 ___ X-1 ___  0  ___  1  ___  2  ___  3  __
+ *         Y-3     Y-3     Y-3     2       2       2       2 
  *
  *       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .
  *
  * Y must be even.  The actual location opposite (0,0) is (X-(Y-1)/2,0),
  * and likewise opposite (0,Y-1) is ((Y-1)/2,0).
  *
- * We label edges as follows:
+ * Note that though presentation above is equilateral triangles, this
+ * is not the case.  It's actually a square lattice with half of the
+ * diagonals added.  We can't straighten it out because at the join
+ * the diagonals point the other way!
  *
- *             e:          \2   /1
- *                          \  /
- *                       ___ 0   __
- *                       3    1   0
- *                          /  \
- *                        4/   5\
+ * We label edges as follows:        Or in the square view:
+ *
+ *                 \2   /1                 2  1  
+ *                  \  /                   | /   
+ *               ___ 0   __                |/    
+ *               3    1   0             3--*--0  
+ *                  /  \                  /|     
+ *                4/   5\                / |     
+ *                                      4  5
+ *
+ *                                   (This makes the numbering
+ *                                   discontinuity, at the join,
+ *                                   vertical and thus tractable.)
  */
 
 #ifndef MGRAPH_H
 
 #include "common.h"
 
-#define XBITS 3
+#define DIMBITS 5
+
+#define XBITS DIMBITS
 #define X (1<<XBITS)
-#define YBITS 3
+#define YBITS DIMBITS
 #define Y (1<<YBITS)
 
 /* vertex number:   0000 | y     | x
index a21dded6765a45618439bbca9ef16de71f7c51cd..42c4019da42d425e3da33b1f672e04319d97bec4 100644 (file)
--- a/primer.c
+++ b/primer.c
@@ -8,21 +8,26 @@
 #include "mgraph.h"
 
 int main(int argc, const char **argv) {
-  int v, k;
+  static const int prec= DBL_DIG+2;
+  int vi, k;
   
   if (argc>1) { fputs("no args please\n",stderr); exit(8); }
 
   printf("print %d, %d, %d, %d, %d\n", DIM, N, X, Y, D3);
   
-  FOR_VERTEX(v) {
-    int x= v & XMASK; /* distance along strip */
-    int y= v >> YSHIFT; /* distance across strip */
-    double u= y * 1.0 / (Y-1);
-    double v= x * M_PI / (X-1); /* SGT's u runs 0..pi along the strip */
-    K printf("print %c%c(%.*g,%.*g)\n",
-            "+-+"[k],
-            "xyz"[k],
-            DBL_DIG+2,u, DBL_DIG+2,v);
+  FOR_VERTEX(vi) {
+    int x= vi & XMASK; /* distance along strip */
+    int y= vi >> YSHIFT; /* distance across strip */
+    double u= y * 1.0 / (Y-1); /* SGT's u runs 0..1 across the strip */
+
+    /* SGT's v runs 0..pi along the strip, where the join is at 0==pi.
+     * So that corresponds to 0..X (since 0==X in our scheme). */
+    double v= x * M_PI / X;
+    
+    K printf("print %c%c( %-*.*g, %-*.*g);  # %03x %2d %2d\n",
+            "+-+"[k], "xyz"[k],
+            prec+5,prec,u, prec+5,prec,v,
+            vi, x, y);
   }
   flushoutput();
   return 0;