From 5a5134e9bd6ec4d32d55616dffad424626fa3384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 2 Jan 2021 12:09:00 +0100 Subject: [PATCH] box-drawing: LIGHT ARC: simpler way to adjust for asymmetrical arc when mirroring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When mirroring an arc, we need to adjust the mirrored position if the arc’s position in the cell is asymmetrical. This happens when *either* the line is odd sized, *or* the cell is. But not when both are. Thus, we can simply do a ‘thickness % 2 ^ width % 2’ when adjusting the position. Describe this in a comment. --- box-drawing.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 31e33528..ba5110ff 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -1241,17 +1241,44 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) * At this point, row/col is only correct for ╯. For the other * arcs, we need to mirror the arc around either the x-, y- or * both axis. + * + * When doing so, we need to adjust for assymetrical cell + * dimensions. + * + * The amazing box drawing art below represents the lower part + * of a cell, with the beginning of a vertical line in the + * middle. Each column represents one pixel. + * + * + * Even cell Odd cell + * + * │ │ │ │ + * Even line │ ┆ ┆ │ │ ┆ ┆ │ + * │ ┆ ┆ │ │ ┆ ┆ │ + * └─┴─┴─┴─┘ └─┴─┴─┴─┴─┘ + * + * + * │ │ │ │ + * Odd line │ ┆ ┆ │ │ ┆ ┆ │ + * │ ┆ ┆ │ │ ┆ ┆ │ + * └─┴─┴─┴─┘ └─┴─┴─┴─┴─┘ + * + * As can be seen(?), the resulting line is assymetrical when + * *either* the cell is odd sized, *or* the line is odd + * sized. But not when both are. + * + * Hence the ‘thick % 2 ^ width % 2’ in the expressions below. */ switch (wc) { case L'╭': - row_end = buf->height - row - (thick % 2 ? 1 - buf->height % 2 : buf->height % 2); + row_end = buf->height - row - (thick % 2 ^ buf->height % 2); row_start = row_end - thick; - col_end = buf->width - col - (thick % 2 ? 1 - buf->width % 2 : buf->width % 2); + col_end = buf->width - col - (thick % 2 ^ buf->width % 2); col_start = col_end - thick; break; case L'╮': - row_end = buf->height - row - (thick % 2 ? 1 - buf->height % 2 : buf->height % 2); + row_end = buf->height - row - (thick % 2 ^ buf->height % 2); row_start = row_end - thick; col_start = col; col_end = col_start + thick; @@ -1260,7 +1287,7 @@ draw_box_drawings_light_arc(wchar_t wc, struct buf *buf) case L'╰': row_start = row; row_end = row_start + thick; - col_end = buf->width - col - (thick % 2 ? 1 - buf->width % 2 : buf->width % 2); + col_end = buf->width - col - (thick % 2 ^ buf->width % 2); col_start = col_end - thick; break;