From 8730f959c86c3b91253e3f91b0225e93db39220d Mon Sep 17 00:00:00 2001 From: Bill Merryman Date: Sat, 1 Nov 2025 15:55:58 -0400 Subject: [PATCH 1/5] create alternative fillCircleHelper --- Adafruit_GFX.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++-- Adafruit_GFX.h | 2 ++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index 5b33ee41..ae3fa52f 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -514,7 +514,7 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, @param x0 Center-point x coordinate @param y0 Center-point y coordinate @param r Radius of circle - @param cornername Mask bit #1 or bit #2 to indicate which quarters of + @param cornername Mask bit #1, #2, #4, and #8 to indicate which quarters of the circle we're doing @param color 16-bit 5-6-5 Color to draw with */ @@ -574,11 +574,12 @@ void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, /**************************************************************************/ /*! - @brief Quarter-circle drawer with fill, used for circles and roundrects + @brief Half-circle drawer with fill, used for circles and roundrects @param x0 Center-point x coordinate @param y0 Center-point y coordinate @param r Radius of circle - @param corners Mask bits indicating which quarters we're doing + @param corners Mask bits indicating which sides of the circle we are doing, + left and/or right @param delta Offset from center-point, used for round-rects @param color 16-bit 5-6-5 Color to fill with */ @@ -625,6 +626,79 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, } } +/**************************************************************************/ +/*! + @brief Quarter-circle drawer with fill. + @param useLegacy uses the half-circle implementation if desired + @param x0 Center-point x coordinate + @param y0 Center-point y coordinate + @param r Radius of circle + @param corners Mask bit #1, #2, #4, and #8 to indicate which quarters of + the circle we're doing + @param delta Offset from center-point. Elongates the horizontal face if desired. + @param color 16-bit 5-6-5 Color to fill with +*/ +/**************************************************************************/ +void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t r, + uint8_t corners, int16_t delta, + uint16_t color) { + + int16_t f = 1 - r; + int16_t ddF_x = 1; + int16_t ddF_y = -2 * r; + int16_t x = 0; + int16_t y = r; + int16_t px = x; + int16_t py = y; + + if(useLegacy){ + fillCircleHelper(x0, y0, r, corners, delta, color); + return; + } + + if (corners & (0x2 | 0x1)) + writeFastVLine(x0, y0 - r, r + 1, color); + if (corners & (0x8 | 0x4)) + writeFastVLine(x0, y0, r + 1, color); + + delta++; // Avoid some +1's in the loop + + while (x < y) { + if (f >= 0) { + y--; + ddF_y += 2; + f += ddF_y; + } + x++; + ddF_x += 2; + f += ddF_x; + // These checks avoid double-drawing certain lines, important + // for the SSD1306 library which has an INVERT drawing mode. + if (x < (y + 1)) { + if (corners & 0x4) + writeFastVLine(x0 + x, y0, y + delta, color); + if (corners & 0x2) + writeFastVLine(x0 + x, y0 - y, y + delta, color); + if (corners & 0x8) + writeFastVLine(x0 - x, y0, y + delta, color); + if (corners & 0x1) + writeFastVLine(x0 - x, y0 - y, y + delta, color); + } + if (y != py) { + if (corners & 0x4) + writeFastVLine(x0 + py, y0, px + delta, color); + if (corners & 0x2) + writeFastVLine(x0 + py, y0 - px, px + delta, color); + if (corners & 0x8) + writeFastVLine(x0 - py, y0, px + delta, color); + if (corners & 0x1) + writeFastVLine(x0 - py, y0 - px, px + delta, color); + py = y; + } + px = x; + } +} + /**************************************************************************/ /*! @brief Draw a rectangle with no fill color diff --git a/Adafruit_GFX.h b/Adafruit_GFX.h index 032d8ea4..5237ff68 100644 --- a/Adafruit_GFX.h +++ b/Adafruit_GFX.h @@ -73,6 +73,8 @@ class Adafruit_GFX : public Print { void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); + void fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t r, + uint8_t corners, int16_t delta, uint16_t color); void drawEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh, uint16_t color); void fillEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh, From 6c8b0932907c4edde257580488bc35f2d35af735 Mon Sep 17 00:00:00 2001 From: Bill Merryman Date: Wed, 5 Nov 2025 17:25:02 -0500 Subject: [PATCH 2/5] create-alt-fillCircleHelper --- Adafruit_GFX.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index ae3fa52f..945dc013 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -514,8 +514,8 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, @param x0 Center-point x coordinate @param y0 Center-point y coordinate @param r Radius of circle - @param cornername Mask bit #1, #2, #4, and #8 to indicate which quarters of - the circle we're doing + @param cornername Mask bit #1, #2, #4, and #8 to indicate which quarters + of the circle we're doing @param color 16-bit 5-6-5 Color to draw with */ /**************************************************************************/ @@ -578,8 +578,8 @@ void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, @param x0 Center-point x coordinate @param y0 Center-point y coordinate @param r Radius of circle - @param corners Mask bits indicating which sides of the circle we are doing, - left and/or right + @param corners Mask bits indicating which sides of the circle we are + doing, left and/or right @param delta Offset from center-point, used for round-rects @param color 16-bit 5-6-5 Color to fill with */ @@ -635,12 +635,13 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, @param r Radius of circle @param corners Mask bit #1, #2, #4, and #8 to indicate which quarters of the circle we're doing - @param delta Offset from center-point. Elongates the horizontal face if desired. + @param delta Offset from center-point. Elongates the horizontal face if + desired. @param color 16-bit 5-6-5 Color to fill with */ /**************************************************************************/ -void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t r, - uint8_t corners, int16_t delta, +void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, + int16_t r, uint8_t corners, int16_t delta, uint16_t color) { int16_t f = 1 - r; @@ -652,8 +653,8 @@ void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int1 int16_t py = y; if(useLegacy){ - fillCircleHelper(x0, y0, r, corners, delta, color); - return; + fillCircleHelper(x0, y0, r, corners, delta, color); + return; } if (corners & (0x2 | 0x1)) From e6725dba69b673fcab76b1cf61d2c63317c15116 Mon Sep 17 00:00:00 2001 From: Bill Merryman Date: Wed, 5 Nov 2025 17:48:38 -0500 Subject: [PATCH 3/5] create-alt-fillCircleHelper --- Adafruit_GFX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index 945dc013..beb5b216 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -652,7 +652,7 @@ void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t px = x; int16_t py = y; - if(useLegacy){ + if (useLegacy) { fillCircleHelper(x0, y0, r, corners, delta, color); return; } From 9ce7065ff71ed8a35d7a810106a5353a1aade257 Mon Sep 17 00:00:00 2001 From: Bill Merryman Date: Thu, 6 Nov 2025 04:22:13 -0500 Subject: [PATCH 4/5] create-alt-fillCircleHelper --- Adafruit_GFX.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index beb5b216..81f33152 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -651,12 +651,12 @@ void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t y = r; int16_t px = x; int16_t py = y; - + if (useLegacy) { fillCircleHelper(x0, y0, r, corners, delta, color); return; } - + if (corners & (0x2 | 0x1)) writeFastVLine(x0, y0 - r, r + 1, color); if (corners & (0x8 | 0x4)) From 19d8848b529be5aefb7347c7b86979371ab6d9a3 Mon Sep 17 00:00:00 2001 From: Bill Merryman Date: Thu, 6 Nov 2025 04:23:40 -0500 Subject: [PATCH 5/5] create-alt-fillCircleHelper --- Adafruit_GFX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index 81f33152..3bce21b3 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -640,7 +640,7 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, @param color 16-bit 5-6-5 Color to fill with */ /**************************************************************************/ -void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, +void Adafruit_GFX::fillCircleHelper(bool useLegacy, int16_t x0, int16_t y0, int16_t r, uint8_t corners, int16_t delta, uint16_t color) {