Skip to content

Commit

Permalink
adagfxswap() renamed and localized to .cpp file to avoid collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
PaintYourDragon committed Jan 26, 2016
1 parent 93dde8b commit f5ec45e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
22 changes: 13 additions & 9 deletions Adafruit_GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ POSSIBILITY OF SUCH DAMAGE.
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif

#ifndef _swap_int16_t
#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
#endif

Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h):
WIDTH(w), HEIGHT(h)
{
Expand Down Expand Up @@ -176,13 +180,13 @@ void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
uint16_t color) {
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
adagfxswap(x0, y0);
adagfxswap(x1, y1);
_swap_int16_t(x0, y0);
_swap_int16_t(x1, y1);
}

if (x0 > x1) {
adagfxswap(x0, x1);
adagfxswap(y0, y1);
_swap_int16_t(x0, x1);
_swap_int16_t(y0, y1);
}

int16_t dx, dy;
Expand Down Expand Up @@ -287,13 +291,13 @@ void Adafruit_GFX::fillTriangle(int16_t x0, int16_t y0,

// Sort coordinates by Y order (y2 >= y1 >= y0)
if (y0 > y1) {
adagfxswap(y0, y1); adagfxswap(x0, x1);
_swap_int16_t(y0, y1); _swap_int16_t(x0, x1);
}
if (y1 > y2) {
adagfxswap(y2, y1); adagfxswap(x2, x1);
_swap_int16_t(y2, y1); _swap_int16_t(x2, x1);
}
if (y0 > y1) {
adagfxswap(y0, y1); adagfxswap(x0, x1);
_swap_int16_t(y0, y1); _swap_int16_t(x0, x1);
}

if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing
Expand Down Expand Up @@ -335,7 +339,7 @@ void Adafruit_GFX::fillTriangle(int16_t x0, int16_t y0,
a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if(a > b) adagfxswap(a,b);
if(a > b) _swap_int16_t(a,b);
drawFastHLine(a, y, b-a+1, color);
}

Expand All @@ -352,7 +356,7 @@ void Adafruit_GFX::fillTriangle(int16_t x0, int16_t y0,
a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
*/
if(a > b) adagfxswap(a,b);
if(a > b) _swap_int16_t(a,b);
drawFastHLine(a, y, b-a+1, color);
}
}
Expand Down
6 changes: 0 additions & 6 deletions Adafruit_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

#include "gfxfont.h"

#define adagfxswap(a, b) { int16_t t = a; a = b; b = t; }

#if !defined(ESP8266)
#define swap(a, b) adagfxswap(a, b)
#endif

class Adafruit_GFX : public Print {

public:
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit GFX Library
version=1.1.3
version=1.1.4
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.
Expand Down

2 comments on commit f5ec45e

@caternuson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This #define was being used in Adafruit_LED_Backpack (maybe others?). Moving it to .cpp file makes it unusable elsewhere.

Ref. this commit: adafruit/Adafruit_LED_Backpack@46873b2

@PaintYourDragon
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads-up, fixed in LEDbackpack now. There will probably be other GFX subclasses where this was overlooked, will update as we find them.
Too-generically-named macros in a class header was an oversight. Surprised this didn't bite us much sooner, really. Anyway, best course of action going forward is probably declaring an equivalent macro within any library .cpp that needs it, as done here. There'll be a transition period as we track them all down.

Please sign in to comment.