Arc - gPC fix by @Brandon502
with fix for missing pixel on 8x32 and similar ratios.
This commit is contained in:
@@ -827,8 +827,8 @@ void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint3
|
|||||||
|
|
||||||
void Segment::drawArc(unsigned x0, unsigned y0, int radius, uint32_t color, uint32_t fillColor) {
|
void Segment::drawArc(unsigned x0, unsigned y0, int radius, uint32_t color, uint32_t fillColor) {
|
||||||
if (!isActive() || (radius <=0)) return; // not active
|
if (!isActive() || (radius <=0)) return; // not active
|
||||||
float minradius = float(radius) - .5;
|
float minradius = float(radius) - .5f;
|
||||||
float maxradius = float(radius) + .5;
|
float maxradius = float(radius) + .5f;
|
||||||
// WLEDMM pre-calculate values to speed up the loop
|
// WLEDMM pre-calculate values to speed up the loop
|
||||||
const int minradius2 = roundf(minradius * minradius);
|
const int minradius2 = roundf(minradius * minradius);
|
||||||
const int maxradius2 = roundf(maxradius * maxradius);
|
const int maxradius2 = roundf(maxradius * maxradius);
|
||||||
@@ -841,17 +841,18 @@ void Segment::drawArc(unsigned x0, unsigned y0, int radius, uint32_t color, uint
|
|||||||
const int starty = max(0, int(y0)-radius-1);
|
const int starty = max(0, int(y0)-radius-1);
|
||||||
const int endy = min(height, 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++) {
|
for (int x=startx; x<endx; x++) {
|
||||||
int newX2 = x - int(x0); newX2 *= newX2; // (distance from centerX) ^2
|
int newX2 = x - int(x0); newX2 *= newX2; // (distance from centerX) ^2
|
||||||
int newY2 = y - int(y0); newY2 *= newY2; // (distance from centerY) ^2
|
for (int y=starty; y<endy; y++) {
|
||||||
int distance2 = newX2 + newY2;
|
int newY2 = y - int(y0); newY2 *= newY2; // (distance from centerY) ^2
|
||||||
|
int distance2 = newX2 + newY2;
|
||||||
if ((distance2 >= minradius2) && (distance2 <= maxradius2)) {
|
if ((distance2 >= minradius2) && (distance2 <= maxradius2)) {
|
||||||
setPixelColorXY(x, y, color);
|
setPixelColorXY(x, y, color);
|
||||||
} else {
|
} else {
|
||||||
if (fillColor != 0)
|
if (fillColor != 0)
|
||||||
if (distance2 < minradius2)
|
if (distance2 < minradius2)
|
||||||
setPixelColorXY(x, y, fillColor);
|
setPixelColorXY(x, y, fillColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -957,6 +957,7 @@ void IRAM_ATTR_YN __attribute__((hot)) Segment::setPixelColor(int i, uint32_t co
|
|||||||
if (i==0)
|
if (i==0)
|
||||||
setPixelColorXY(0, 0, col);
|
setPixelColorXY(0, 0, col);
|
||||||
else {
|
else {
|
||||||
|
if (i == virtualLength() - 1) setPixelColorXY(vW-1, vH-1, col); // Last i always fill corner
|
||||||
if (!_isSuperSimpleSegment) {
|
if (!_isSuperSimpleSegment) {
|
||||||
// WLEDMM: drawArc() is faster if it's NOT "super simple" as the regular M12_pArc
|
// 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
|
// can do "useSymmetry" to speed things along, but a more complicated segment likey
|
||||||
@@ -1227,10 +1228,20 @@ uint32_t __attribute__((hot)) Segment::getPixelColor(int i) const
|
|||||||
return vW>vH ? getPixelColorXY(i, 0) : getPixelColorXY(0, i); // Corner and Arc
|
return vW>vH ? getPixelColorXY(i, 0) : getPixelColorXY(0, i); // Corner and Arc
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int length = virtualLength();
|
float minradius = float(i) - .5f;
|
||||||
int x = i * vW / length;
|
const int minradius2 = roundf(minradius * minradius);
|
||||||
int y = i * vH / length;
|
int startX, startY;
|
||||||
return getPixelColorXY(x, y); // Not 100% accurate
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getPixelColorXY(vW-1, vH-1); // Last pixel
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M12_jMap: //WLEDMM jMap
|
case M12_jMap: //WLEDMM jMap
|
||||||
|
|||||||
Reference in New Issue
Block a user