From 8a0b97e0a8611a578567cf73a9e35a90ebf48670 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 25 Feb 2024 19:46:53 +0100 Subject: [PATCH] ARC mapping optimization The biggest optimization was to avoid sin_t / cos_t. Now let's try to help the compiler optimize the drawing loop. --- wled00/FX_fcn.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 7b517769..e8a3217f 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -889,13 +889,19 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT else { //WLEDMM: drawArc(0, 0, i, col); could work as alternative - float step = HALF_PI / (2.85f*i); - for (float rad = 0.0f; rad <= HALF_PI+step/2; rad += step) { + //WLEDMM: some opimizations for the drawing loop + float radius = float(i); // pre-calculate, for some speed + float step = HALF_PI / (2.85f * radius); + unsigned numSteps = 1 + ((HALF_PI + step/2.0f) / step); // pre-calculate, so the compiler can better optimize the for loop + float rad = 0.0f; + for (unsigned count = 0; count < numSteps; count++) { // may want to try float version as well (with or without antialiasing) - int x = roundf(sinf(rad) * i); - int y = roundf(cosf(rad) * i); + int x = roundf(sinf(rad) * radius); + int y = roundf(cosf(rad) * radius); setPixelColorXY(x, y, col); + rad += step; } + // Bresenham’s Algorithm (may not fill every pixel) //int d = 3 - (2*i); //int y = i, x = 0;