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) {
|
||||
if (!isActive() || (radius <=0)) return; // not active
|
||||
float minradius = float(radius) - .5;
|
||||
float maxradius = float(radius) + .5;
|
||||
float minradius = float(radius) - .5f;
|
||||
float maxradius = float(radius) + .5f;
|
||||
// WLEDMM pre-calculate values to speed up the loop
|
||||
const int minradius2 = roundf(minradius * minradius);
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -957,6 +957,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
|
||||
@@ -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
|
||||
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) - .5f;
|
||||
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);
|
||||
}
|
||||
}
|
||||
return getPixelColorXY(vW-1, vH-1); // Last pixel
|
||||
break;
|
||||
}
|
||||
case M12_jMap: //WLEDMM jMap
|
||||
|
||||
Reference in New Issue
Block a user