Skip to content

Commit

Permalink
Graphics: Fix issue where drawLine for 2px horizontal lines only drew…
Browse files Browse the repository at this point in the history
… a 1px dot
  • Loading branch information
gfwilliams committed Nov 8, 2024
1 parent 6b565f8 commit f6493d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
RegExp: add optimisation for RegExp that is simply checking if a string ends with something
Bangle.js: .setUI now only clears back widget if it hasn't been hidden by widget_utils
Fix UtilTimer timings when new task added infront of existing tasks (fix #2575)
Graphics: Fix issue where drawLine for 2px horizontal lines only drew a 1px dot

2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()'
Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off)
Expand Down
8 changes: 4 additions & 4 deletions libs/graphics/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,14 @@ void graphicsDrawLine(JsGraphics *gfx, int x1, int y1, int x2, int y2) {

int xl = x2-x1;
int yl = y2-y1;
if (xl<0) xl=-xl; else if (xl==0) xl=1;
if (yl<0) yl=-yl; else if (yl==0) yl=1;
if (xl<0) xl=-xl;
if (yl<0) yl=-yl;
if (xl > yl) { // longer in X - scan in X
if (x1>x2) {
int t;
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
}
} else if (xl==0) xl=1;
int pos = (y1<<8) + 128; // rounding!
int step = ((y2-y1)<<8) / xl;
int x;
Expand All @@ -665,7 +665,7 @@ void graphicsDrawLine(JsGraphics *gfx, int x1, int y1, int x2, int y2) {
int t;
t = x1; x1 = x2; x2 = t;
t = y1; y1 = y2; y2 = t;
}
} else if (yl==0) yl=1;
int pos = (x1<<8) + 128; // rounding!
int step = ((x2-x1)<<8) / yl;
int y;
Expand Down
14 changes: 10 additions & 4 deletions tests/test_graphics_drawLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ g.setColor(9).setBgColor(0);
g.drawLine(1,1,14,8);
g.drawLineAA(1,1+4,14,8+4);

g.setColor(1);
g.drawLine(10,0,10,0);
g.drawLine(10,1,11,1);
g.drawLine(10,2,12,2);
g.drawLine(10,3,13,3);

SHOULD_BE(`
@
@@
@@
.
@ ..
@@ ...
@@ ....
@@
@= @@
+%= @@
Expand Down

0 comments on commit f6493d5

Please sign in to comment.