Skip to content

Commit 1350a41

Browse files
committed
Arc optimization: symmety at 45degress
If the segment is wider than 20 pixels, we optimize calculations due to symmetry - for smaller arcs the result looks better without optimization. As a side-effect, we have enough computing power left to go through the complete circumference, avoiding holes.
1 parent 9f5a75f commit 1350a41

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

wled00/FX_fcn.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,23 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
889889
else {
890890
//WLEDMM: drawArc(0, 0, i, col); could work as alternative
891891

892-
//WLEDMM: some opimizations for the drawing loop
893-
float radius = float(i); // pre-calculate, for some speed
894-
float step = HALF_PI / (2.85f * radius);
895-
unsigned numSteps = 1 + ((HALF_PI + step/2.0f) / step); // pre-calculate, so the compiler can better optimize the for loop
892+
//WLEDMM: some optimizations for the drawing loop
893+
// pre-calculate loop limits, exploit symmetry at 45deg
894+
float radius = float(i);
895+
// float step = HALF_PI / (2.85f * radius); // upstream uses this
896+
float step = HALF_PI / (M_PI * radius); // WLEDMM we use the correct circumference
897+
bool useSymmetry = (max(vH, vW) > 20); // for segments wider than 20 pixels, we exploit symmetry
898+
unsigned numSteps;
899+
if (useSymmetry) numSteps = 1 + ((HALF_PI/2.0f + step/2.0f) / step); // with symmetry
900+
else numSteps = 1 + ((HALF_PI + step/2.0f) / step); // without symmetry
901+
896902
float rad = 0.0f;
897903
for (unsigned count = 0; count < numSteps; count++) {
898904
// may want to try float version as well (with or without antialiasing)
899905
int x = roundf(sinf(rad) * radius);
900906
int y = roundf(cosf(rad) * radius);
901907
setPixelColorXY(x, y, col);
908+
if(useSymmetry) setPixelColorXY(y, x, col);// WLEDMM
902909
rad += step;
903910
}
904911

0 commit comments

Comments
 (0)