Send commitlog mailing list submissions to
        commitlog@lists.openmoko.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
        commitlog-requ...@lists.openmoko.org

You can reach the person managing the list at
        commitlog-ow...@lists.openmoko.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:

   1. r5706 - developers/werner/cncmap/zmap (wer...@docs.openmoko.org)
   2. r5707 - developers/werner/cncmap/zmap (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2009-10-23 23:44:49 +0200 (Fri, 23 Oct 2009)
New Revision: 5706

Modified:
   developers/werner/cncmap/zmap/try.c
   developers/werner/cncmap/zmap/zline.c
   developers/werner/cncmap/zmap/zline.h
Log:
Preparing zmap for batch use.

- zmap/zline.c (zpoint): map just a single point (for holes)
- zmap/try.c: added single point and file mode



Modified: developers/werner/cncmap/zmap/try.c
===================================================================
--- developers/werner/cncmap/zmap/try.c 2009-10-22 23:52:25 UTC (rev 5705)
+++ developers/werner/cncmap/zmap/try.c 2009-10-23 21:44:49 UTC (rev 5706)
@@ -1,18 +1,91 @@
+/*
+ * main.c - Command-line interface to zmap and zline
+ *
+ * Written 2009 by Werner Almesberger
+ * Copyright 2009 Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
 #include <stdlib.h>
 #include <stdio.h>
+#include <math.h>
 
+#include "zmap.h"
 #include "zline.h"
 
 
-static void point (void *user, double x, double y, double z)
+#define EPSILON        0.001   /* 1 um */
+
+
+struct line {
+       struct xyz a, b;
+};
+
+
+static void point(void *user, double x, double y, double z)
 {
        printf("%f %f %f\n", x, y, z);
 }
 
 
+static void point_3d(void *user, double x, double y, double z)
+{
+       const struct line *line = user;
+       double len, pos;
+       double f;
+
+       len = hypot(line->b.x-line->a.x, line->b.y-line->a.y);
+       pos = hypot(x-line->a.x, y-line->a.y);
+       f = len < EPSILON ? 0.5 : pos/len;
+               f = 0.5;
+       z += f*line->b.z+(1-f)*line->a.z;
+       point(NULL, x, y, z);
+}
+
+
+static void process_file(FILE *file)
+{
+       int lineno = 0;
+       char buf[1024];
+       struct line line;
+       int first = 1;
+       int n;
+
+       while (fgets(buf, sizeof(buf), file)) {
+               lineno++;
+               n = sscanf(buf, "%lf %lf %lf\n",
+                   &line.b.x, &line.b.y, &line.b.z);
+               switch (n) {
+               case -1:
+                       printf("\n");
+                       first = 1;
+                       continue;
+               case 2:
+                       line.b.z = 0;
+                       /* fall through */
+               case 3:
+                       break;
+               default:
+                       fprintf(stderr, "invalid data at line %d\n", lineno);
+                       exit(1);
+               }
+               if (!first)
+                       zline(line.a.x, line.a.y, line.b.x, line.b.y,
+                           point_3d, &line);
+               line.a = line.b;
+               first = 0;
+       }
+}
+
+
 static void usage(const char *name)
 {
-       fprintf(stderr, "usage: %s zmap xa ya xb yb\n", name);
+       fprintf(stderr, "usage: %s zmap_file [xa ya [xb yb]]\n", name);
        exit(1);
 }
 
@@ -23,15 +96,32 @@
        double p[4];
        int i;
 
-       if (argc != 6)
+       switch (argc) {
+       case 2:
+               break;
+       case 4:
+       case 6:
+               for (i = 2; i != argc; i++) {
+                       p[i-2] = strtod(argv[i], &end);
+                       if (*end)
+                               usage(*argv);
+               }
+               break;
+       default:
                usage(*argv);
+       }
        zline_init(argv[1]);
-       for (i = 0; i != 4; i++) {
-               p[i] = strtod(argv[i+2], &end);
-               if (*end)
-                       usage(*argv);
+       switch (argc) {
+       case 2:
+               process_file(stdin);
+               break;
+       case 4:
+               zpoint(p[0], p[1], point, NULL);
+               break;
+       case 6:
+               zline(p[0], p[1], p[2], p[3], point, NULL);
+               break;
        }
-       zline(p[0], p[1], p[2], p[3], point, NULL);
        zline_end();
        return 0;
 }

Modified: developers/werner/cncmap/zmap/zline.c
===================================================================
--- developers/werner/cncmap/zmap/zline.c       2009-10-22 23:52:25 UTC (rev 
5705)
+++ developers/werner/cncmap/zmap/zline.c       2009-10-23 21:44:49 UTC (rev 
5706)
@@ -130,9 +130,9 @@
 
        assert(map_n >= 3);
        zmap_sort(map, map_n, xa, ya);
-       proj = zmap_project(map, map_n, xa, ya, xb, yb);
        point(user, xa, ya, zmap_point(map[0], map[1], map[2], xa, ya));
 
+       proj = zmap_project(map, map_n, xa, ya, xb, yb);
        t = 0;
        while (1) {
                best_t = 1;
@@ -163,6 +163,19 @@
 }
 
 
+/*
+ * Like zline, but do just the first point.
+ */
+
+void zpoint(double x, double y,
+    void (*point)(void *user, double x, double y, double z), void *user)
+{
+       assert(map_n >= 3);
+       zmap_sort(map, map_n, x, y);
+       point(user, x, y, zmap_point(map[0], map[1], map[2], x, y));
+}
+
+
 void zline_end(void)
 {
        free(map);

Modified: developers/werner/cncmap/zmap/zline.h
===================================================================
--- developers/werner/cncmap/zmap/zline.h       2009-10-22 23:52:25 UTC (rev 
5705)
+++ developers/werner/cncmap/zmap/zline.h       2009-10-23 21:44:49 UTC (rev 
5706)
@@ -17,6 +17,8 @@
 void zline_init(const char *name);
 void zline(double xa, double ya, double xb, double yb,
     void (*point)(void *user, double x, double y, double z), void *user);
+void zpoint(double x, double y,
+    void (*point)(void *user, double x, double y, double z), void *user);
 void zline_end(void);
 
 #endif /* ZLINE_H */




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2009-10-23 23:47:40 +0200 (Fri, 23 Oct 2009)
New Revision: 5707

Added:
   developers/werner/cncmap/zmap/main.c
Removed:
   developers/werner/cncmap/zmap/try.c
Modified:
   developers/werner/cncmap/zmap/Makefile
Log:
- renamed command-line utility from "zline" to "zmap"
- zmap/try.c: renamed to zmap/main.c



Modified: developers/werner/cncmap/zmap/Makefile
===================================================================
--- developers/werner/cncmap/zmap/Makefile      2009-10-23 21:44:49 UTC (rev 
5706)
+++ developers/werner/cncmap/zmap/Makefile      2009-10-23 21:47:40 UTC (rev 
5707)
@@ -11,9 +11,9 @@
 #
 
 
-MAIN=zline
+MAIN=zmap
 
-OBJS=try.o zline.o zmap.o
+OBJS=main.o zline.o zmap.o
 
 CFLAGS = -g -Wall -Wshadow
 LDFLAGS = -lm

Copied: developers/werner/cncmap/zmap/main.c (from rev 5706, 
developers/werner/cncmap/zmap/try.c)
===================================================================
--- developers/werner/cncmap/zmap/main.c                                (rev 0)
+++ developers/werner/cncmap/zmap/main.c        2009-10-23 21:47:40 UTC (rev 
5707)
@@ -0,0 +1,127 @@
+/*
+ * main.c - Command-line interface to zmap and zline
+ *
+ * Written 2009 by Werner Almesberger
+ * Copyright 2009 Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "zmap.h"
+#include "zline.h"
+
+
+#define EPSILON        0.001   /* 1 um */
+
+
+struct line {
+       struct xyz a, b;
+};
+
+
+static void point(void *user, double x, double y, double z)
+{
+       printf("%f %f %f\n", x, y, z);
+}
+
+
+static void point_3d(void *user, double x, double y, double z)
+{
+       const struct line *line = user;
+       double len, pos;
+       double f;
+
+       len = hypot(line->b.x-line->a.x, line->b.y-line->a.y);
+       pos = hypot(x-line->a.x, y-line->a.y);
+       f = len < EPSILON ? 0.5 : pos/len;
+               f = 0.5;
+       z += f*line->b.z+(1-f)*line->a.z;
+       point(NULL, x, y, z);
+}
+
+
+static void process_file(FILE *file)
+{
+       int lineno = 0;
+       char buf[1024];
+       struct line line;
+       int first = 1;
+       int n;
+
+       while (fgets(buf, sizeof(buf), file)) {
+               lineno++;
+               n = sscanf(buf, "%lf %lf %lf\n",
+                   &line.b.x, &line.b.y, &line.b.z);
+               switch (n) {
+               case -1:
+                       printf("\n");
+                       first = 1;
+                       continue;
+               case 2:
+                       line.b.z = 0;
+                       /* fall through */
+               case 3:
+                       break;
+               default:
+                       fprintf(stderr, "invalid data at line %d\n", lineno);
+                       exit(1);
+               }
+               if (!first)
+                       zline(line.a.x, line.a.y, line.b.x, line.b.y,
+                           point_3d, &line);
+               line.a = line.b;
+               first = 0;
+       }
+}
+
+
+static void usage(const char *name)
+{
+       fprintf(stderr, "usage: %s zmap_file [xa ya [xb yb]]\n", name);
+       exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+       char *end;
+       double p[4];
+       int i;
+
+       switch (argc) {
+       case 2:
+               break;
+       case 4:
+       case 6:
+               for (i = 2; i != argc; i++) {
+                       p[i-2] = strtod(argv[i], &end);
+                       if (*end)
+                               usage(*argv);
+               }
+               break;
+       default:
+               usage(*argv);
+       }
+       zline_init(argv[1]);
+       switch (argc) {
+       case 2:
+               process_file(stdin);
+               break;
+       case 4:
+               zpoint(p[0], p[1], point, NULL);
+               break;
+       case 6:
+               zline(p[0], p[1], p[2], p[3], point, NULL);
+               break;
+       }
+       zline_end();
+       return 0;
+}

Deleted: developers/werner/cncmap/zmap/try.c
===================================================================
--- developers/werner/cncmap/zmap/try.c 2009-10-23 21:44:49 UTC (rev 5706)
+++ developers/werner/cncmap/zmap/try.c 2009-10-23 21:47:40 UTC (rev 5707)
@@ -1,127 +0,0 @@
-/*
- * main.c - Command-line interface to zmap and zline
- *
- * Written 2009 by Werner Almesberger
- * Copyright 2009 Werner Almesberger
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-
-#include "zmap.h"
-#include "zline.h"
-
-
-#define EPSILON        0.001   /* 1 um */
-
-
-struct line {
-       struct xyz a, b;
-};
-
-
-static void point(void *user, double x, double y, double z)
-{
-       printf("%f %f %f\n", x, y, z);
-}
-
-
-static void point_3d(void *user, double x, double y, double z)
-{
-       const struct line *line = user;
-       double len, pos;
-       double f;
-
-       len = hypot(line->b.x-line->a.x, line->b.y-line->a.y);
-       pos = hypot(x-line->a.x, y-line->a.y);
-       f = len < EPSILON ? 0.5 : pos/len;
-               f = 0.5;
-       z += f*line->b.z+(1-f)*line->a.z;
-       point(NULL, x, y, z);
-}
-
-
-static void process_file(FILE *file)
-{
-       int lineno = 0;
-       char buf[1024];
-       struct line line;
-       int first = 1;
-       int n;
-
-       while (fgets(buf, sizeof(buf), file)) {
-               lineno++;
-               n = sscanf(buf, "%lf %lf %lf\n",
-                   &line.b.x, &line.b.y, &line.b.z);
-               switch (n) {
-               case -1:
-                       printf("\n");
-                       first = 1;
-                       continue;
-               case 2:
-                       line.b.z = 0;
-                       /* fall through */
-               case 3:
-                       break;
-               default:
-                       fprintf(stderr, "invalid data at line %d\n", lineno);
-                       exit(1);
-               }
-               if (!first)
-                       zline(line.a.x, line.a.y, line.b.x, line.b.y,
-                           point_3d, &line);
-               line.a = line.b;
-               first = 0;
-       }
-}
-
-
-static void usage(const char *name)
-{
-       fprintf(stderr, "usage: %s zmap_file [xa ya [xb yb]]\n", name);
-       exit(1);
-}
-
-
-int main(int argc, char **argv)
-{
-       char *end;
-       double p[4];
-       int i;
-
-       switch (argc) {
-       case 2:
-               break;
-       case 4:
-       case 6:
-               for (i = 2; i != argc; i++) {
-                       p[i-2] = strtod(argv[i], &end);
-                       if (*end)
-                               usage(*argv);
-               }
-               break;
-       default:
-               usage(*argv);
-       }
-       zline_init(argv[1]);
-       switch (argc) {
-       case 2:
-               process_file(stdin);
-               break;
-       case 4:
-               zpoint(p[0], p[1], point, NULL);
-               break;
-       case 6:
-               zline(p[0], p[1], p[2], p[3], point, NULL);
-               break;
-       }
-       zline_end();
-       return 0;
-}




--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog

Reply via email to