chiark / gitweb /
Emit open contours starting at the beginning.
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 8 Aug 2017 22:23:55 +0000 (23:23 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 8 Aug 2017 22:23:55 +0000 (23:23 +0100)
Before this change, emit_path() would emit contours starting at
whichever point was earliest in the points array.  That was fine for
closed contours, but it meant the open contours tended to be emitted
in multiple parts.  Now it first searches for start points of open
contours and emits those, and then does what it used to do to emit the
remaining (closed) ones.  This has no effect (other than to slow
things down a bit) for fully-closed paths like those in outline
versions of Bedstead, but it makes the stroked ones much cleaner.  Now
a contour can only end at a tip or at a 3-way junction.

bedstead.c

index 47b94694baf5e5575a05bc92e69e1c01ae05113a..9bfad09a4065e9edbd25dc7f0f2b0d57a8781fc4 100644 (file)
@@ -1978,16 +1978,22 @@ emit_contour(point *p0)
 static void 
 emit_path()
 {
-       int i;
+       int i, pass;
        point *p, *p1;
        bool started = false;
 
-       for (i = 0; i < nextpoint; i++) {
-               p = &points[i];
-               if (p->next) {
-                       if (!started) printf("Fore\nSplineSet\n");
-                       started = true;
-                       emit_contour(p);
+       /*
+        * On the first pass, emit open contours (if there are any).
+        * On the second pass, emit all remaining contours.
+        */
+       for (pass = 0; pass <= 1; pass++) {
+               for (i = 0; i < nextpoint; i++) {
+                       p = &points[i];
+                       if (p->next && (!p->prev || pass == 1)) {
+                               if (!started) printf("Fore\nSplineSet\n");
+                               started = true;
+                               emit_contour(p);
+                       }
                }
        }
        if (started) printf("EndSplineSet\n");