Fixes #2034: ldc_line() was wrong for slanted lines

This commit is contained in:
Damjan Adamic
2015-01-23 18:12:33 +01:00
parent d6b67899ff
commit f131119ca1
3 changed files with 33 additions and 6 deletions
+6 -6
View File
@@ -490,28 +490,28 @@ void lcd_line(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFl
if (dxabs >= dyabs) {
/* the line is more horizontal than vertical */
for (int i=0; i<=dxabs; i++) {
if ((1<<(px%8)) & pat) {
lcd_plot(px, py, att);
}
y += dyabs;
if (y>=dxabs) {
y -= dxabs;
py += sdy;
}
if ((1<<(px%8)) & pat) {
lcd_plot(px, py, att);
}
px += sdx;
}
}
else {
/* the line is more vertical than horizontal */
for (int i=0; i<=dyabs; i++) {
if ((1<<(py%8)) & pat) {
lcd_plot(px, py, att);
}
x += dxabs;
if (x >= dyabs) {
x -= dyabs;
px += sdx;
}
if ((1<<(py%8)) & pat) {
lcd_plot(px, py, att);
}
py += sdy;
}
}
+27
View File
@@ -438,6 +438,33 @@ TEST(Lcd, lcd_line)
lcd_line(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
lcd_line(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
// 45 deg lines
lcd_line( 35, 40, 45, 40, SOLID, FORCE );
lcd_line( 40, 35, 40, 45, SOLID, FORCE );
lcd_line( 20, 40, 40, 20, SOLID, FORCE );
lcd_line( 40, 20, 60, 40, SOLID, FORCE );
lcd_line( 60, 40, 40, 60, SOLID, FORCE );
lcd_line( 40, 60, 20, 40, SOLID, FORCE );
lcd_line( 31, 39, 39, 31, SOLID, FORCE );
lcd_line( 41, 31, 49, 39, SOLID, FORCE );
lcd_line( 49, 41, 41, 49, SOLID, FORCE );
lcd_line( 39, 49, 31, 41, SOLID, FORCE );
// slanted lines
lcd_line( 150, 10, 190, 10, SOLID, FORCE );
lcd_line( 150, 10, 190, 20, SOLID, FORCE );
lcd_line( 150, 10, 190, 30, SOLID, FORCE );
lcd_line( 150, 10, 190, 40, SOLID, FORCE );
lcd_line( 150, 10, 190, 50, SOLID, FORCE );
lcd_line( 150, 10, 190, 50, SOLID, FORCE );
lcd_line( 150, 10, 180, 50, SOLID, FORCE );
lcd_line( 150, 10, 170, 50, SOLID, FORCE );
lcd_line( 150, 10, 160, 50, SOLID, FORCE );
lcd_line( 150, 10, 150, 50, SOLID, FORCE );
EXPECT_TRUE(checkScreenshot("lcd_line"));
}
#endif
Binary file not shown.

Before

Width:  |  Height:  |  Size: 454 B

After

Width:  |  Height:  |  Size: 1.0 KiB