From 70df58c53bdd2c2b0de6a93e6c7c480730e6732a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 31 Dec 2007 15:52:53 +0000 Subject: [PATCH] tidyings, more points. --- Makefile | 7 ++++--- energy.c | 6 +++--- mgraph.c | 16 ---------------- mgraph.h | 42 +++++++++++++++++++++++++++--------------- primer.c | 25 +++++++++++++++---------- 5 files changed, 49 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index 39d43e3..bec227e 100644 --- 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 diff --git a/energy.c b/energy.c index ce78a54..d673c14 100644 --- 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; diff --git a/mgraph.c b/mgraph.c index c66ef48..cf57624 100644 --- 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]; diff --git a/mgraph.h b/mgraph.h index acbe5c4..0870489 100644 --- 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 * * . . . . . . . . . . . . . . . * @@ -33,14 +33,24 @@ * 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 @@ -48,9 +58,11 @@ #include "common.h" -#define XBITS 3 +#define DIMBITS 5 + +#define XBITS DIMBITS #define X (1<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; -- 2.30.2