Skip to content

Commit 8a12e0a

Browse files
DaveSpraguemarcelstoer
authored andcommitted
Corrected circle drawing algorithm (#197)
1 parent 8d62d9c commit 8a12e0a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/OLEDDisplay.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ void OLEDDisplay::drawCircle(int16_t x0, int16_t y0, int16_t radius) {
159159
int16_t dp = 1 - radius;
160160
do {
161161
if (dp < 0)
162-
dp = dp + 2 * (++x) + 3;
162+
dp = dp + 2 * (x++) + 3;
163163
else
164-
dp = dp + 2 * (++x) - 2 * (--y) + 5;
164+
dp = dp + 2 * (x++) - 2 * (y--) + 5;
165165

166166
setPixel(x0 + x, y0 + y); //For the 8 octants
167167
setPixel(x0 - x, y0 + y);
@@ -185,9 +185,9 @@ void OLEDDisplay::drawCircleQuads(int16_t x0, int16_t y0, int16_t radius, uint8_
185185
int16_t dp = 1 - radius;
186186
while (x < y) {
187187
if (dp < 0)
188-
dp = dp + 2 * (++x) + 3;
188+
dp = dp + 2 * (x++) + 3;
189189
else
190-
dp = dp + 2 * (++x) - 2 * (--y) + 5;
190+
dp = dp + 2 * (x++) - 2 * (y--) + 5;
191191
if (quads & 0x1) {
192192
setPixel(x0 + x, y0 - y);
193193
setPixel(x0 + y, y0 - x);
@@ -225,9 +225,9 @@ void OLEDDisplay::fillCircle(int16_t x0, int16_t y0, int16_t radius) {
225225
int16_t dp = 1 - radius;
226226
do {
227227
if (dp < 0)
228-
dp = dp + 2 * (++x) + 3;
228+
dp = dp + 2 * (x++) + 3;
229229
else
230-
dp = dp + 2 * (++x) - 2 * (--y) + 5;
230+
dp = dp + 2 * (x++) - 2 * (y--) + 5;
231231

232232
drawHorizontalLine(x0 - x, y0 - y, 2*x);
233233
drawHorizontalLine(x0 - x, y0 + y, 2*x);

0 commit comments

Comments
 (0)