Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[BUG] GFX line drawing mishandles start/end values

When drawing lines of equal start and end x, y coordinates the GFX library shall draw a rectangle with thickness applied. If the value of the opposing axis has a start value greater than the end value this results in a line drawn in the opposite direction. Tested with nRF5 SDK 15.0.0 a53641a.

Here is a patch which uses MIN() for drawing the rectangle (line):

--- components/libraries/gfx/nrf_gfx.c	2018-03-22 15:25:07.608481800 +0100
+++ components/libraries/gfx/nrf_gfx.c	2018-03-22 15:25:07.608481800 +0100
@@ -265,8 +265,8 @@
     if ((p_line->x_start == p_line->x_end) || (p_line->y_start == p_line->y_end))
     {
         rect_draw(p_instance,
-                  p_line->x_start,
-                  p_line->y_start,
+                  MIN(p_line->x_start, p_line->x_end),
+                  MIN(p_line->y_start, p_line->y_end),
                   abs(p_line->x_end - p_line->x_start) + x_thick,
                   abs(p_line->y_end - p_line->y_start) + y_thick,
                   color);

Related