Skip to content

Commit 49d826d

Browse files
committed
Tidy up setGeometry checks
- Improve early stop check - Remove redundant Y size check
1 parent 83816b4 commit 49d826d

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

wled00/FX_fcn.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ void Segment::handleRandomPalette() {
459459

460460
void Segment::setGeometry(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, uint16_t ofs, uint16_t i1Y, uint16_t i2Y, uint8_t m12) {
461461
// Sanitise inputs
462-
if (i2 < i1) { // For any values, this means "stop"; we do i2 before i1 for this case
462+
if (i2 <= i1) { // For any values, this means deactivate the segment; we check i2 before i1 for this case
463463
i2 = 0;
464464
} else {
465465
// Clamp i2 to maximum length
@@ -474,7 +474,7 @@ void Segment::setGeometry(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, ui
474474
// If i1 is invalid, use old value
475475
// Valid range is inside maxWidth, or in trailing segment range
476476
if ((i1 >= Segment::maxWidth) && (i1 < Segment::maxWidth*Segment::maxHeight || i1 >= strip.getLengthTotal())) {
477-
i1 = start;
477+
i1 = start;
478478
}
479479

480480
#ifndef WLED_DISABLE_2D
@@ -485,9 +485,6 @@ void Segment::setGeometry(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, ui
485485
} else if (i2Y < 1) {
486486
i2Y = 1;
487487
}
488-
if (i2Y < i1Y) {
489-
i2 = 0; // stop
490-
}
491488
} else
492489
#endif
493490
{
@@ -499,7 +496,7 @@ void Segment::setGeometry(uint16_t i1, uint16_t i2, uint8_t grp, uint8_t spc, ui
499496
if (ofs == UINT16_MAX) ofs = offset;
500497
m12 = constrain(m12, 0, 7);
501498

502-
// Final safety check
499+
// Final safety check after all bounds adjustments
503500
if ((i1 >= i2) || (i1Y >= i2Y)) {
504501
i2 = 0; // disable segment
505502
}

0 commit comments

Comments
 (0)