chiark / gitweb /
Start path simplification for skeleton font.
authorBen Harris <bjh21@bjh21.me.uk>
Mon, 17 Jul 2017 22:22:38 +0000 (23:22 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Mon, 17 Jul 2017 22:22:38 +0000 (23:22 +0100)
This finds places where multiple segments can be replaced by a single
straight line and so replaces them.

bedstead.c

index 45fc759ceb16d4220231eb2ff15226a22b6c0006..cc9b71b868a4501f71f2fca10a56ac4b14e01a0f 100644 (file)
@@ -1898,6 +1898,48 @@ dochar(char const data[YSIZE], unsigned flags)
        emit_path();
 }
 
+/* Join together two points each at the end of a path */
+static void
+join_ends(point *a, point *b)
+{
+       assert(a->next == NULL);
+       assert(a->prev != NULL);
+       assert(b->prev == NULL);
+       assert(b->next != NULL);
+       a->next = b;
+       b->prev = a;
+       fix_identical(a); /* Will delete a */
+       fix_collinear(b); /* Will delete b */
+}
+
+static bool
+point_endp(point *p)
+{
+       return p->next == NULL || p->prev == NULL;
+}
+
+static void
+clean_skeleton()
+{
+       int i, j;
+
+       for (i = 0; i < nextpoint; i++) {
+               if (points[i].prev == NULL && points[i].next == NULL)
+                       continue;
+               for (j = 0; j < nextpoint; j++) {
+                       if (points[j].prev == NULL && points[j].next == NULL)
+                               continue;
+                       if (vec_eqp(points[i].v, points[j].v) &&
+                           points[i].next == NULL && points[j].prev == NULL &&
+                           vec_inline3(points[i].prev->v, points[i].v,
+                                       points[j].next->v))
+                               join_ends(&points[i], &points[j]);
+                       if (points[i].prev == NULL && points[i].next == NULL)
+                               break;
+               }
+       }
+}
+
 static void
 dochar_plotter(char const data[YSIZE], unsigned flags)
 {
@@ -1919,6 +1961,7 @@ dochar_plotter(char const data[YSIZE], unsigned flags)
                        }
                }
        }
+       clean_skeleton();
        emit_path();
 }