@@ -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
137139void 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
145149void 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
163169void 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
171179void 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-
196202void 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);
0 commit comments