From 1c59350995d808851ec803611ff7fbf232848d27 Mon Sep 17 00:00:00 2001 From: Bill Merryman Date: Fri, 7 Nov 2025 08:41:24 -0500 Subject: [PATCH 1/3] Add quarter circle draw method --- Adafruit_GFX.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ Adafruit_GFX.h | 2 ++ 2 files changed, 69 insertions(+) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index 5b33ee41..7710ff93 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -625,6 +625,73 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, } } +/**************************************************************************/ +/*! + @brief Quarter-circle drawer with fill. + @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::fillQuarterCircle(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 (corners & (0x2 | 0x1)) + writeFastVLine(x0, y0 - r, r + 1, color); + if (corners & (0x8 | 0x4)) + writeFastVLine(x0, y0, r + 1, color); + + delta++; + + while (x < y) { + if (f >= 0) { + y--; + ddF_y += 2; + f += ddF_y; + } + x++; + ddF_x += 2; + f += ddF_x; + + 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..cf6487da 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 fillQuarterCircle(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 18e6e8bbfdbb431a1806392ed362109c638bbe95 Mon Sep 17 00:00:00 2001 From: Bill Merryman Date: Fri, 7 Nov 2025 08:53:44 -0500 Subject: [PATCH 2/3] Add quarter circle draw method (formatting) --- Adafruit_GFX.cpp | 6 +++--- Adafruit_GFX.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index 7710ff93..0f12d972 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -638,9 +638,9 @@ 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::fillQuarterCircle(int16_t x0, int16_t y0, - int16_t r, uint8_t corners, int16_t delta, - uint16_t color) { +void Adafruit_GFX::fillQuarterCircle(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; diff --git a/Adafruit_GFX.h b/Adafruit_GFX.h index cf6487da..e9802fb1 100644 --- a/Adafruit_GFX.h +++ b/Adafruit_GFX.h @@ -73,8 +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 fillQuarterCircle(int16_t x0, int16_t y0, int16_t r, - uint8_t corners, int16_t delta, uint16_t color); + void fillQuarterCircle(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 5ec6f8e1d7ca89570a2c19aab9c6dcacf6335dfe Mon Sep 17 00:00:00 2001 From: Bill Merryman Date: Fri, 7 Nov 2025 15:10:51 -0500 Subject: [PATCH 3/3] Add quarter circle draw method (update briefs) --- Adafruit_GFX.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index 0f12d972..e2faf995 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -631,10 +631,11 @@ void Adafruit_GFX::fillCircleHelper(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 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 corners Mask bits 0x1, 0x2, 0x4, and 0x8 to indicate which quarters + of the circle to fill: 0x1 = top-left, 0x2 = top-right, + 0x4 = bottom-right, 0x8 = bottom-left + @param delta Offset from center-point. Elongates the horizontal face (by + extending the vertical lines) if desired. @param color 16-bit 5-6-5 Color to fill with */ /**************************************************************************/