summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2015-03-15 21:51:46 (GMT)
committerWerner Almesberger <werner@almesberger.net>2015-03-15 21:51:46 (GMT)
commit1f33a9716932836c257295dd02f1f24abcb0eb4f (patch)
treeb1f52c8005ec5b73c36c72678be580511fe2bd1f /meme
parent57ff0b618c936a0f48d445f78beaeb6b7b000f59 (diff)
downloadmisc-1f33a9716932836c257295dd02f1f24abcb0eb4f.zip
misc-1f33a9716932836c257295dd02f1f24abcb0eb4f.tar.gz
misc-1f33a9716932836c257295dd02f1f24abcb0eb4f.tar.bz2
meme/: generalize overlay handling (let caller provide coordinate transform)
This will let us share the code with vispcb.
Diffstat (limited to 'meme')
-rw-r--r--meme/meme.c11
-rw-r--r--meme/overlay.c17
-rw-r--r--meme/overlay.h5
3 files changed, 24 insertions, 9 deletions
diff --git a/meme/meme.c b/meme/meme.c
index 4480f3f..2a8d11b 100644
--- a/meme/meme.c
+++ b/meme/meme.c
@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include <math.h>
#include "time.h"
#include "mesh.h"
@@ -52,6 +53,13 @@ static void slice_out(double x, double y, double z, bool last)
}
+static void overlay_xform(float x, float y, float *res_x, float *res_y)
+{
+ *res_x = round(x * 1000);
+ *res_y = round(y * 1000);
+}
+
+
static void usage(const char *name)
{
fprintf(stderr,
@@ -85,7 +93,8 @@ int main(int argc, char **argv)
fprintf(stderr, "too many overlays\n");
exit(1);
}
- overlays[n_overlays] = overlay_load(optarg);
+ overlays[n_overlays] = overlay_load(optarg,
+ overlay_xform);
n_overlays++;
break;
case 's':
diff --git a/meme/overlay.c b/meme/overlay.c
index fd85de4..70bf4e2 100644
--- a/meme/overlay.c
+++ b/meme/overlay.c
@@ -13,7 +13,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include <math.h>
#include "util.h"
#include "overlay.h"
@@ -46,7 +45,8 @@ void overlay_draw(const struct overlay *overlay,
}
-static struct overlay *overlay_load_file(FILE *file)
+static struct overlay *overlay_load_file(FILE *file,
+ void (*xform)(float x, float y, float *res_x, float *res_y))
{
struct overlay *over = NULL;
struct overlay *path = NULL;
@@ -81,8 +81,12 @@ static struct overlay *overlay_load_file(FILE *file)
over = path;
}
p = alloc_type(struct point);
- p->x = round(x * 1000);
- p->y = round(y * 1000);
+ if (xform) {
+ xform(x, y, &p->x, &p->y);
+ } else {
+ p->x = x;
+ p->y = y;
+ }
p->next = path->points;
path->points = p;
}
@@ -90,7 +94,8 @@ static struct overlay *overlay_load_file(FILE *file)
}
-struct overlay *overlay_load(const char *name)
+struct overlay *overlay_load(const char *name,
+ void (*xform)(float x, float y, float *res_x, float *res_y))
{
FILE *file;
struct overlay *over;
@@ -100,7 +105,7 @@ struct overlay *overlay_load(const char *name)
perror(name);
exit(1);
}
- over = overlay_load_file(file);
+ over = overlay_load_file(file, xform);
fclose(file);
return over;
}
diff --git a/meme/overlay.h b/meme/overlay.h
index dbab8b3..2439608 100644
--- a/meme/overlay.h
+++ b/meme/overlay.h
@@ -20,6 +20,7 @@ struct overlay;
void overlay_draw(const struct overlay *overlay,
void (*moveto)(void *user, int x, int y),
void (*lineto)(void *user, int x, int y), void *user);
-struct overlay *overlay_load(const char *name);
+struct overlay *overlay_load(const char *name,
+ void (*xform)(float x, float y, float *res_x, float *res_y));
-#endif /* !STL_H */
+#endif /* !OVERLAY_H */