Skip to content

Commit cb95e03

Browse files
drawLine(): sort inputs on horizontal/vertical lines
C'mon guys, this is Graphics 101 stuff
1 parent 7be06d3 commit cb95e03

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Adafruit_GFX.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ void Adafruit_GFX::writePixel(int16_t x, int16_t y, uint16_t color){
134134
drawPixel(x, y, color);
135135
}
136136

137+
// (x,y) is topmost point; if unsure, calling function
138+
// should sort endpoints or call writeLine() instead
137139
void Adafruit_GFX::writeFastVLine(int16_t x, int16_t y,
138140
int16_t h, uint16_t color) {
139141
// Overwrite in subclasses if startWrite is defined!
@@ -142,6 +144,8 @@ void Adafruit_GFX::writeFastVLine(int16_t x, int16_t y,
142144
drawFastVLine(x, y, h, color);
143145
}
144146

147+
// (x,y) is leftmost point; if unsure, calling function
148+
// should sort endpoints or call writeLine() instead
145149
void Adafruit_GFX::writeFastHLine(int16_t x, int16_t y,
146150
int16_t w, uint16_t color) {
147151
// Overwrite in subclasses if startWrite is defined!
@@ -160,6 +164,8 @@ void Adafruit_GFX::endWrite(){
160164
// Overwrite in subclasses if startWrite is defined!
161165
}
162166

167+
// (x,y) is topmost point; if unsure, calling function
168+
// should sort endpoints or call drawLine() instead
163169
void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y,
164170
int16_t h, uint16_t color) {
165171
// Update in subclasses if desired!
@@ -168,6 +174,8 @@ void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y,
168174
endWrite();
169175
}
170176

177+
// (x,y) is leftmost point; if unsure, calling function
178+
// should sort endpoints or call drawLine() instead
171179
void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y,
172180
int16_t w, uint16_t color) {
173181
// Update in subclasses if desired!
@@ -191,15 +199,15 @@ void Adafruit_GFX::fillScreen(uint16_t color) {
191199
fillRect(0, 0, _width, _height, color);
192200
}
193201

194-
#define distDiff(a,b) ((max(a,b) - min(a,b))+1)
195-
196202
void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
197203
uint16_t color) {
198204
// Update in subclasses if desired!
199205
if(x0 == x1){
200-
drawFastVLine(x0, y0, distDiff(y0,y1), color);
206+
if(y0 > y1) _swap_int16_t(y0, y1);
207+
drawFastVLine(x0, y0, y1 - y0 + 1, color);
201208
} else if(y0 == y1){
202-
drawFastHLine(x0, y0, distDiff(x0,x1), color);
209+
if(x0 > x1) _swap_int16_t(x0, x1);
210+
drawFastHLine(x0, y0, x1 - x0 + 1, color);
203211
} else {
204212
startWrite();
205213
writeLine(x0, y0, x1, y1, color);

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit GFX Library
2-
version=1.1.8
2+
version=1.1.9
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.

0 commit comments

Comments
 (0)