From: Ben Harris Date: Mon, 17 Jul 2017 22:22:38 +0000 (+0100) Subject: Start path simplification for skeleton font. X-Git-Tag: bedstead-002.000~128 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=537479b72896014800586e4381d70229fc5a22fd;p=bedstead.git Start path simplification for skeleton font. This finds places where multiple segments can be replaced by a single straight line and so replaces them. --- diff --git a/bedstead.c b/bedstead.c index 45fc759..cc9b71b 100644 --- a/bedstead.c +++ b/bedstead.c @@ -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(); }