From 950c1b6010efe07a9a65116618a980179ed279a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 3 Aug 2021 21:12:13 +0200 Subject: [PATCH] box-drawing: pre-calculate sextant x,y offsets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’re using floating point math, as a way to ensure that sextant primitives overlap, rather than leaving empty spaces, or being uneven, when the cell width/height isn’t divisible with 2 (width) or 3 (height). This gets rid of all floating point math from the sextant drawing functions. --- box-drawing.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/box-drawing.c b/box-drawing.c index 63e8034a..5e511262 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -29,7 +29,12 @@ struct buf { float cell_size; float base_thickness; bool solid_shades; + int thickness[2]; + + /* For sextants and wedges */ + int x_halfs[2]; + int y_thirds[4]; }; static const pixman_color_t white = {0xffff, 0xffff, 0xffff, 0xffff}; @@ -1956,37 +1961,37 @@ draw_quadrant(struct buf *buf, wchar_t wc) static void sextant_upper_left(struct buf *buf) { - rect(0, 0, round(buf->width / 2.), round(buf->height / 3.)); + rect(0, 0, buf->x_halfs[0], buf->y_thirds[0]); } static void sextant_middle_left(struct buf *buf) { - rect(0, buf->height / 3, round(buf->width / 2.), round(2. * buf->height / 3.)); + rect(0, buf->y_thirds[1], buf->x_halfs[0], buf->y_thirds[2]); } static void sextant_lower_left(struct buf *buf) { - rect(0, 2 * buf->height / 3, round(buf->width / 2.), buf->height); + rect(0, buf->y_thirds[3], buf->x_halfs[0], buf->height); } static void sextant_upper_right(struct buf *buf) { - rect(buf->width / 2, 0, buf->width, round(buf->height / 3.)); + rect(buf->x_halfs[1], 0, buf->width, buf->y_thirds[0]); } static void sextant_middle_right(struct buf *buf) { - rect(buf->width / 2, buf->height / 3, buf->width, round(2. * buf->height / 3.)); + rect(buf->x_halfs[1], buf->y_thirds[1], buf->width, buf->y_thirds[2]); } static void sextant_lower_right(struct buf *buf) { - rect(buf->width / 2, 2 * buf->height / 3, buf->width, buf->height); + rect(buf->x_halfs[1], buf->y_thirds[3], buf->width, buf->height); } static void @@ -2759,6 +2764,14 @@ box_drawing(const struct terminal *term, wchar_t wc) buf.thickness[LIGHT] = _thickness(&buf, LIGHT); buf.thickness[HEAVY] = _thickness(&buf, HEAVY); + buf.x_halfs[0] = round(width / 2.); /* End point first half */ + buf.x_halfs[1] = width / 2; /* Start point second half */ + + buf.y_thirds[0] = round(height / 3.); /* End point first third */ + buf.y_thirds[1] = height / 3; /* Start point second third */ + buf.y_thirds[2] = round(2. * height / 3.); /* End point second third */ + buf.y_thirds[3] = 2 * height / 3; /* Start point last third */ + LOG_DBG("LIGHT=%d, HEAVY=%d", _thickness(&buf, LIGHT), _thickness(&buf, HEAVY));