From e15c501919cf4be902116f6dd147fa3ed31bc48b Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 16 Jul 2025 21:43:29 +0100 Subject: [PATCH] Improve drawing of lines - Draw a pixel at the start of the line - Avoid gaps rendering fractional coordinates --- src/draw/engine_display_draw.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/draw/engine_display_draw.c b/src/draw/engine_display_draw.c index e893b8e0..faaa0029 100644 --- a/src/draw/engine_display_draw.c +++ b/src/draw/engine_display_draw.c @@ -1,6 +1,7 @@ #include "draw/engine_display_draw.h" #include "display/engine_display_common.h" #include "debug/debug_print.h" +#include #include #include @@ -58,12 +59,7 @@ void engine_draw_line(uint16_t color, float x_start, float y_start, float x_end, float dy = y_end - y_start; // See which axis requires most steps to draw complete line, store it - float step_count = 0.0f; - if(abs((int)dx) >= abs((int)dy)){ - step_count = abs((int)dx); - }else{ - step_count = abs((int)dy); - } + float step_count = ceilf(fmax(fabs(dx), fabs(dy))); // Calculate how much to increment each axis each step float slope_x = dx / step_count; @@ -73,11 +69,11 @@ void engine_draw_line(uint16_t color, float x_start, float y_start, float x_end, float line_y = y_start; // Draw the line - for(uint32_t step=0; step