refactor(ui): share Bresenham line + midpoint circle in GfxUtils.h

drawLine was duplicated verbatim in TrailScreen and CompassScreen, and
drawCircle lived only in CompassScreen. Lift both into a gfx:: namespace
header so the map and compass share one copy of each 1-px primitive.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-06-04 00:13:44 +02:00
co-authored by Claude Opus 4.8
parent 55d164c074
commit a5d55a38b9
3 changed files with 46 additions and 44 deletions
+2 -14
View File
@@ -7,6 +7,7 @@
#include "../Trail.h"
#include "../GeoUtils.h"
#include "GfxUtils.h"
#include "NavView.h"
#include <math.h>
@@ -733,7 +734,7 @@ private:
drawFilledDot(display, x0, y0);
drawOpenDot(display, x1, y1);
} else {
drawLine(display, x0, y0, x1, y1);
gfx::drawLine(display, x0, y0, x1, y1);
}
x0 = x1;
y0 = y1;
@@ -882,19 +883,6 @@ private:
display.print(lbl);
}
static void drawLine(DisplayDriver& d, int x0, int y0, int x1, int y1) {
int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
int dy = -abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
int err = dx + dy;
while (true) {
d.fillRect(x0, y0, 1, 1);
if (x0 == x1 && y0 == y1) break;
int e2 = err * 2;
if (e2 >= dy) { err += dy; x0 += sx; }
if (e2 <= dx) { err += dx; y0 += sy; }
}
}
static void drawFilledDot(DisplayDriver& d, int cx, int cy) {
d.fillRect(cx - 1, cy - 1, 3, 3);
}