summaryrefslogtreecommitdiff
path: root/meme
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-05-11 19:46:35 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-05-11 19:49:03 (GMT)
commit49ffe0b41738d365d01f09f230955f0f404784a8 (patch)
tree78110ada216c9914d93e04e3d1477bcba22b963e /meme
parent412272b7cbe2c67b3dcd2d6ac56b5b4ea5a742e8 (diff)
downloadmisc-49ffe0b41738d365d01f09f230955f0f404784a8.zip
misc-49ffe0b41738d365d01f09f230955f0f404784a8.tar.gz
misc-49ffe0b41738d365d01f09f230955f0f404784a8.tar.bz2
meme/marker.c, README: support six-number format, with text offset
Diffstat (limited to 'meme')
-rw-r--r--meme/README4
-rw-r--r--meme/marker.c39
2 files changed, 34 insertions, 9 deletions
diff --git a/meme/README b/meme/README
index def617b..c3d6531 100644
--- a/meme/README
+++ b/meme/README
@@ -113,6 +113,10 @@ x y text
A marker indicating a measurement between points A and B is defined with
ax ay bx by text
+The latter form can be extended with an offset (using the same coordinate
+system) that is added to the start position of the text:
+ax ay bx by ox oy text
+
Slicing
-------
diff --git a/meme/marker.c b/meme/marker.c
index 31f9e95..5f76601 100644
--- a/meme/marker.c
+++ b/meme/marker.c
@@ -22,6 +22,7 @@
struct mark {
float xa, ya, xb, yb;
+ float ox, oy; /* offset for text */
const char *s;
struct mark *next;
};
@@ -53,8 +54,8 @@ void marker_draw(const struct marker *marker,
dy = -dy;
}
- x = (mark->xa + mark->xb) / 2.0;
- y = (mark->ya + mark->yb) / 2.0;
+ x = (mark->xa + mark->xb) / 2.0 + mark->ox;
+ y = (mark->ya + mark->yb) / 2.0 + mark->oy;
line(user, mark->xa, mark->ya, mark->xb, mark->yb,
dy / d, -dx / d);
@@ -69,7 +70,7 @@ static void marker_load_file(struct marker *marker, FILE *file,
int lineno = 0;
char buf[1024];
int n;
- double xa, ya, xb, yb;
+ double xa, ya, xb, yb, ox, oy;
char *s;
struct mark *mark;
@@ -78,15 +79,21 @@ static void marker_load_file(struct marker *marker, FILE *file,
lineno++;
if (*buf == '#')
continue;
- n = sscanf(buf, "%lf %lf %lf %lf %m[^\n]",
- &xa, &ya, &xb, &yb, &s);
- if (n != 5)
- n = sscanf(buf, "%lf %lf %m[^\n]\n", &xa, &ya, &s);
+ n = sscanf(buf, "%lf %lf %lf %lf %lf %lf %m[^\n]",
+ &xa, &ya, &xb, &yb, &ox, &oy, &s);
+ if (n != 7) {
+ n = sscanf(buf, "%lf %lf %lf %lf %m[^\n]",
+ &xa, &ya, &xb, &yb, &s);
+ if (n != 5)
+ n = sscanf(buf, "%lf %lf %m[^\n]\n",
+ &xa, &ya, &s);
+ }
switch (n) {
case -1:
continue;
case 3:
case 5:
+ case 7:
break;
default:
fprintf(stderr, "invalid data at line %d\n", lineno);
@@ -101,18 +108,32 @@ static void marker_load_file(struct marker *marker, FILE *file,
mark->xa = xa;
mark->ya = ya;
}
+ mark->ox = mark->oy = 0;
mark->s = s;
- if (n == 3) {
+ switch (n) {
+ case 3:
mark->xb = mark->xa;
mark->yb = mark->ya;
- } else {
+ break;
+ case 7:
+ if (xform) {
+ xform(ox, oy, &mark->ox, &mark->oy);
+ } else {
+ mark->ox = ox;
+ mark->oy = oy;
+ }
+ /* fall through */
+ case 5:
if (xform) {
xform(xb, yb, &mark->xb, &mark->yb);
} else {
mark->xb = xb;
mark->yb = yb;
}
+ break;
+ default:
+ abort();
}
marker->markers = mark;
}