@@ -353,7 +353,7 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
353353
354354/* *************************************************************************/
355355/* !
356- @brief Quarter-circle drawer, used to do circles and roundrects
356+ @brief Quarter-circle drawer, used to do circles and roundrects
357357 @param x0 Center-point x coordinate
358358 @param y0 Center-point y coordinate
359359 @param r Radius of circle
@@ -417,25 +417,29 @@ void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,
417417
418418/* *************************************************************************/
419419/* !
420- @brief Quarter-circle drawer with fill, used to do circles and roundrects
421- @param x0 Center-point x coordinate
422- @param y0 Center-point y coordinate
423- @param r Radius of circle
424- @param cornername Mask bit #1 or bit #2 to indicate which quarters of the circle we're doing
425- @param delta Offset from center-point, used for round-rects
426- @param color 16-bit 5-6-5 Color to fill with
420+ @brief Quarter-circle drawer with fill, used for circles and roundrects
421+ @param x0 Center-point x coordinate
422+ @param y0 Center-point y coordinate
423+ @param r Radius of circle
424+ @param corners Mask bits indicating which quarters we're doing
425+ @param delta Offset from center-point, used for round-rects
426+ @param color 16-bit 5-6-5 Color to fill with
427427*/
428428/* *************************************************************************/
429429void Adafruit_GFX::fillCircleHelper (int16_t x0, int16_t y0, int16_t r,
430- uint8_t cornername , int16_t delta, uint16_t color) {
430+ uint8_t corners , int16_t delta, uint16_t color) {
431431
432432 int16_t f = 1 - r;
433433 int16_t ddF_x = 1 ;
434434 int16_t ddF_y = -2 * r;
435435 int16_t x = 0 ;
436436 int16_t y = r;
437+ int16_t px = x;
438+ int16_t py = y;
437439
438- while (x<y) {
440+ delta++; // Avoid some +1's in the loop
441+
442+ while (x < y) {
439443 if (f >= 0 ) {
440444 y--;
441445 ddF_y += 2 ;
@@ -444,15 +448,18 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
444448 x++;
445449 ddF_x += 2 ;
446450 f += ddF_x;
447-
448- if (cornername & 0x1 ) {
449- writeFastVLine (x0+x, y0-y, 2 *y+1 +delta, color);
450- writeFastVLine (x0+y, y0-x, 2 *x+1 +delta, color);
451+ // These checks avoid double-drawing certain lines, important
452+ // for the SSD1306 library which has an INVERT drawing mode.
453+ if (x < (y + 1 )) {
454+ if (corners & 1 ) writeFastVLine (x0+x, y0-y, 2 *y+delta, color);
455+ if (corners & 2 ) writeFastVLine (x0-x, y0-y, 2 *y+delta, color);
451456 }
452- if (cornername & 0x2 ) {
453- writeFastVLine (x0-x, y0-y, 2 *y+1 +delta, color);
454- writeFastVLine (x0-y, y0-x, 2 *x+1 +delta, color);
457+ if (y != py) {
458+ if (corners & 1 ) writeFastVLine (x0+py, y0-px, 2 *px+delta, color);
459+ if (corners & 2 ) writeFastVLine (x0-py, y0-px, 2 *px+delta, color);
460+ py = y;
455461 }
462+ px = x;
456463 }
457464}
458465
0 commit comments