Skip to content

Commit

Permalink
Arc - gPC fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon502 committed Oct 18, 2024
1 parent a0f790d commit 32c9546
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
24 changes: 13 additions & 11 deletions wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,17 +841,19 @@ void Segment::drawArc(unsigned x0, unsigned y0, int radius, uint32_t color, uint
const int starty = max(0, int(y0)-radius-1);
const int endy = min(height, int(y0)+radius+1);

for (int x=startx; x<endx; x++) for (int y=starty; y<endy; y++) {
int newX2 = x - int(x0); newX2 *= newX2; // (distance from centerX) ^2
int newY2 = y - int(y0); newY2 *= newY2; // (distance from centerY) ^2
int distance2 = newX2 + newY2;

if ((distance2 >= minradius2) && (distance2 <= maxradius2)) {
setPixelColorXY(x, y, color);
} else {
if (fillColor != 0)
if (distance2 < minradius2)
setPixelColorXY(x, y, fillColor);
for (int x=startx; x<endx; x++) {
int newX2 = x - int(x0); newX2 *= newX2; // (distance from centerX) ^2
for (int y=starty; y<endy; y++) {
int newY2 = y - int(y0); newY2 *= newY2; // (distance from centerY) ^2
int distance2 = newX2 + newY2;

if ((distance2 >= minradius2) && (distance2 <= maxradius2)) {
setPixelColorXY(x, y, color);
} else {
if (fillColor != 0)
if (distance2 < minradius2)
setPixelColorXY(x, y, fillColor);
}
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,6 @@ uint16_t Segment::virtualLength() const {
break;
case M12_pArc:
vLen = sqrt16(vW * vW + vH * vH);
if (vW != vH) vLen++; // round up
break;
case M12_jMap: //WLEDMM jMap
if (jMap)
Expand Down Expand Up @@ -957,6 +956,7 @@ void IRAM_ATTR_YN __attribute__((hot)) Segment::setPixelColor(int i, uint32_t co
if (i==0)
setPixelColorXY(0, 0, col);
else {
if (i == virtualLength() - 1) setPixelColorXY(vW-1, vH-1, col); // Last i always fill corner
if (!_isSuperSimpleSegment) {
// WLEDMM: drawArc() is faster if it's NOT "super simple" as the regular M12_pArc
// can do "useSymmetry" to speed things along, but a more complicated segment likey
Expand Down Expand Up @@ -1227,10 +1227,20 @@ uint32_t __attribute__((hot)) Segment::getPixelColor(int i) const
return vW>vH ? getPixelColorXY(i, 0) : getPixelColorXY(0, i); // Corner and Arc
break;
}
int length = virtualLength();
int x = i * vW / length;
int y = i * vH / length;
return getPixelColorXY(x, y); // Not 100% accurate
float minradius = float(i) - .5;
const int minradius2 = roundf(minradius * minradius);
int startX, startY;
if (vW >= vH) {startX = vW - 1; startY = 1;} // Last Column
else {startX = 1; startY = vH - 1;} // Last Row

// Loop through only last row/column depending on orientation
for (int x = startX; x < vW; x++) {
int newX2 = x * x;
for (int y = startY; y < vH; y++) {
int newY2 = y * y;
if (newX2 + newY2 >= minradius2) return getPixelColorXY(x, y);
}
}
break;
}
case M12_jMap: //WLEDMM jMap
Expand Down

0 comments on commit 32c9546

Please sign in to comment.