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
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 ----------*/
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;
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];
/*
* 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
#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;