Fix in is2D()
Vertical & horizontal 1D segment (on 2D matrix) Index overshooting fix.
This commit is contained in:
parent
cf0f0d77be
commit
e14c5bbd25
@ -501,7 +501,7 @@ typedef struct Segment {
|
||||
inline bool getOption(uint8_t n) const { return ((options >> n) & 0x01); }
|
||||
inline bool isSelected(void) const { return selected; }
|
||||
inline bool isActive(void) const { return stop > start; }
|
||||
inline bool is2D(void) const { return !(startY == 0 && stopY == 1); }
|
||||
inline bool is2D(void) const { return (width()>1 && height()>1); }
|
||||
inline uint16_t width(void) const { return stop - start; } // segment width in physical pixels (length if 1D)
|
||||
inline uint16_t height(void) const { return stopY - startY; } // segment height (if 2D) in physical pixels
|
||||
inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels
|
||||
|
@ -150,6 +150,7 @@ uint16_t IRAM_ATTR Segment::XY(uint16_t x, uint16_t y) {
|
||||
void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
|
||||
{
|
||||
if (!strip.isMatrix) return; // not a matrix set-up
|
||||
if (x >= virtualWidth() || y >= virtualHeight()) return; // if pixel would fall out of virtual segment just exit
|
||||
|
||||
if (leds) leds[XY(x,y)] = col;
|
||||
|
||||
|
@ -442,11 +442,16 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
|
||||
break;
|
||||
case M12_Circle:
|
||||
// expand in circular fashion from center
|
||||
for (float degrees = 0.0f; degrees <= 90.0f; degrees += 89.99f / (sqrtf((float)max(vH,vW))*i+1)) { // this may prove too many iterations on larger matrices
|
||||
// may want to try float version as well (with or without antialiasing)
|
||||
int x = roundf(sin_t(degrees*DEG_TO_RAD) * i);
|
||||
int y = roundf(cos_t(degrees*DEG_TO_RAD) * i);
|
||||
setPixelColorXY(x, y, col);
|
||||
if (i==0)
|
||||
setPixelColorXY(0, 0, col);
|
||||
else {
|
||||
float step = HALF_PI / (2*i+1); // sqrtf((float)max(vH,vW))*i+1
|
||||
for (float rad = 0.0f; rad <= HALF_PI; rad += step) {
|
||||
// may want to try float version as well (with or without antialiasing)
|
||||
int x = roundf(sin_t(rad) * i);
|
||||
int y = roundf(cos_t(rad) * i);
|
||||
setPixelColorXY(x, y, col);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case M12_Block:
|
||||
@ -455,9 +460,16 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
|
||||
break;
|
||||
}
|
||||
return;
|
||||
} else if (width()==1 && height()>1) {
|
||||
// we have a vertical 1D segment
|
||||
setPixelColorXY(0, i, col); // transpose
|
||||
} else if (width()>1 && height()==1) {
|
||||
// we have a horizontal 1D segment
|
||||
setPixelColorXY(i, 0, col);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (i >= virtualLength()) return; // if pixel would fall out of segment just exit
|
||||
if (leds) leds[i] = col;
|
||||
|
||||
uint16_t len = length();
|
||||
|
Loading…
Reference in New Issue
Block a user