r5703 - developers/werner/cncmap/zmap
werner at docs.openmoko.org
werner at docs.openmoko.org
Thu Oct 22 23:23:06 CEST 2009
Author: werner
Date: 2009-10-22 23:23:05 +0200 (Thu, 22 Oct 2009)
New Revision: 5703
Modified:
developers/werner/cncmap/zmap/zline.c
developers/werner/cncmap/zmap/zmap.c
Log:
Make zline work as designed. Now, improve the design ...
- zmap/zline.c (zline): if selecting the last point, make sure we don't swap
back the point we're trying to get rid of
- zmap: cleaned up debugging output
Modified: developers/werner/cncmap/zmap/zline.c
===================================================================
--- developers/werner/cncmap/zmap/zline.c 2009-10-22 16:33:34 UTC (rev 5702)
+++ developers/werner/cncmap/zmap/zline.c 2009-10-22 21:23:05 UTC (rev 5703)
@@ -20,6 +20,13 @@
#include "zline.h"
+#if 0
+#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
+#else
+#define DEBUG(...) do ; while (0)
+#endif
+
+
static struct xyz *map; /* Z map */
static struct proj *proj;
static int map_n;
@@ -74,12 +81,9 @@
dy = proj[i].d-proj[ref].d;
pos = x+y*dy/dx/b/b;
-fprintf(stderr, "? (%g, %g) [%g %g] (%g, %g) [%g %g] @ %g\n",
- map[ref].x, map[ref].y, proj[ref].t, proj[ref].d,
- map[i].x, map[i].y, proj[i].t, proj[i].d, pos);
-#if 0
-fprintf(stderr, " x %g y %g dx %g dy %g\n", x, y, dx, dy);
-#endif
+ DEBUG("? (%g, %g) [%g %g] (%g, %g) [%g %g] @ %g\n",
+ map[ref].x, map[ref].y, proj[ref].t, proj[ref].d,
+ map[i].x, map[i].y, proj[i].t, proj[i].d, pos);
if (pos < best_t) {
best_t = pos;
best_point = i;
@@ -132,14 +136,13 @@
t = 0;
n = map_n;
-fprintf(stderr, "n %d\n", map_n);
- while (n >= 3) {
+ while (n > 3) {
best_t = 1;
best_next = best_old = -1;
for (i = 0; i != 3; i++) {
tmp_t = t;
tmp_i = next_closest(xa, ya, xb, yb, i, 3, n, &tmp_t);
-fprintf(stderr, "%d: i = %d t = %g\n", i, tmp_i, tmp_t);
+ DEBUG("%d: i = %d t = %g (@%g)\n", i, tmp_i, tmp_t, t);
if (tmp_t < best_t) {
best_t = tmp_t;
best_next = tmp_i;
@@ -148,8 +151,10 @@
}
if (best_next == -1)
break;
+ DEBUG("swap %d vs. %d of %d\n", best_old, best_next, n);
swap(best_old, n-1);
- swap(best_old, best_next);
+ if (best_next != n-1)
+ swap(best_old, best_next);
n--;
t = best_t;
x = xa+(xb-xa)*t;
Modified: developers/werner/cncmap/zmap/zmap.c
===================================================================
--- developers/werner/cncmap/zmap/zmap.c 2009-10-22 16:33:34 UTC (rev 5702)
+++ developers/werner/cncmap/zmap/zmap.c 2009-10-22 21:23:05 UTC (rev 5703)
@@ -18,6 +18,13 @@
#include "zmap.h"
+#if 0
+#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
+#else
+#define DEBUG(...) do ; while (0)
+#endif
+
+
struct xyz *zmap_read(const char *name, int *n)
{
FILE *file;
@@ -86,8 +93,8 @@
t = ((map[i].x-xa)*xb+(map[i].y-ya)*yb)/b/b;
p[i].t = t;
p[i].d = hypot(xa+xb*t-map[i].x, ya+yb*t-map[i].y);
-fprintf(stderr, "PROJ %g %g -> t %g d %g\n",
- map[i].x, map[i].y, p[i].t, p[i].d);
+ DEBUG("PROJ %g %g -> t %g d %g\n",
+ map[i].x, map[i].y, p[i].t, p[i].d);
}
return p;
}
@@ -117,8 +124,8 @@
double xv, yv, zv, v;
double s, t;
-fprintf(stderr, "point (%g, %g) -> (%g, %g) (%g, %g) (%g, %g)\n",
- x, y, a.x, a.y, b.x, b.y, c.x, c.y);
+ DEBUG("point (%g, %g) -> (%g, %g) (%g, %g) (%g, %g)\n",
+ x, y, a.x, a.y, b.x, b.y, c.x, c.y);
xp = x-a.x;
yp = y-a.y;
More information about the commitlog
mailing list