Fix in is2D()

Horizontal and vertical 1D segment
Index overshoot fix.
This commit is contained in:
Blaž Kristan 2022-08-22 14:35:34 +02:00
parent b722c618bd
commit 1711ac9a88
3 changed files with 19 additions and 6 deletions

View File

@ -501,7 +501,7 @@ typedef struct Segment {
inline bool getOption(uint8_t n) const { return ((options >> n) & 0x01); } inline bool getOption(uint8_t n) const { return ((options >> n) & 0x01); }
inline bool isSelected(void) const { return selected; } inline bool isSelected(void) const { return selected; }
inline bool isActive(void) const { return stop > start; } 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 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 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 inline uint16_t length(void) const { return width() * height(); } // segment length (count) in physical pixels

View File

@ -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) void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
{ {
if (!strip.isMatrix) return; // not a matrix set-up 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; if (leds) leds[XY(x,y)] = col;

View File

@ -442,12 +442,17 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
break; break;
case M12_Circle: case M12_Circle:
// expand in circular fashion from center // 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 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) // may want to try float version as well (with or without antialiasing)
int x = roundf(sin_t(degrees*DEG_TO_RAD) * i); int x = roundf(sin_t(rad) * i);
int y = roundf(cos_t(degrees*DEG_TO_RAD) * i); int y = roundf(cos_t(rad) * i);
setPixelColorXY(x, y, col); setPixelColorXY(x, y, col);
} }
}
break; break;
case M12_Block: case M12_Block:
for (int x = 0; x <= i; x++) setPixelColorXY(x, i, col); for (int x = 0; x <= i; x++) setPixelColorXY(x, i, col);
@ -455,9 +460,16 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
break; break;
} }
return; 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 #endif
if (i >= virtualLength()) return; // if pixel would fall out of segment just exit
if (leds) leds[i] = col; if (leds) leds[i] = col;
uint16_t len = length(); uint16_t len = length();