-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Arc Expand Optimizations #4994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Arc Expand Optimizations #4994
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -663,7 +663,7 @@ uint16_t Segment::virtualLength() const { | |
| vLen = max(vW,vH); // get the longest dimension | ||
| break; | ||
| case M12_pArc: | ||
| vLen = sqrt32_bw(vH*vH + vW*vW); // use diagonal | ||
| vLen = (sqrt32_bw((vH*vH + vW*vW) << 2) + 1) >> 1; // diagonal rounded | ||
| break; | ||
| case M12_sPinwheel: | ||
| vLen = getPinwheelLength(vW, vH); | ||
|
|
@@ -742,36 +742,25 @@ void WLED_O2_ATTR Segment::setPixelColor(int i, uint32_t col) const | |
| if (vStrip > 0) setPixelColorRaw(XY(vStrip - 1, vH - i - 1), col); | ||
| else for (int x = 0; x < vW; x++) setPixelColorRaw(XY(x, vH - i - 1), col); | ||
| break; | ||
| case M12_pArc: | ||
| case M12_pArc: { | ||
| // expand in circular fashion from center | ||
| if (i == 0) | ||
| setPixelColorRaw(XY(0, 0), col); | ||
| else { | ||
| float r = i; | ||
| float step = HALF_PI / (2.8284f * r + 4); // we only need (PI/4)/(r/sqrt(2)+1) steps | ||
| for (float rad = 0.0f; rad <= (HALF_PI/2)+step/2; rad += step) { | ||
| int x = roundf(sin_t(rad) * r); | ||
| int y = roundf(cos_t(rad) * r); | ||
| // exploit symmetry | ||
| if (i == 0) setPixelColorXY(0, 0, col); | ||
| else if (i == 2) setPixelColorXY(1, 1, col); | ||
blazoncek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| int x = 0, y = i; // i is the radius | ||
| int d = -(i >> 1); // Initial decision parameter | ||
|
|
||
| // Barrera's circle algorithm | ||
blazoncek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| while (x <= y) { | ||
| if (!(i == x && i == y)) { // prevent early square | ||
blazoncek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setPixelColorXY(x, y, col); | ||
| setPixelColorXY(y, x, col); | ||
| } | ||
| // Bresenham’s Algorithm (may not fill every pixel) | ||
| //int d = 3 - (2*i); | ||
| //int y = i, x = 0; | ||
| //while (y >= x) { | ||
| // setPixelColorXY(x, y, col); | ||
| // setPixelColorXY(y, x, col); | ||
| // x++; | ||
| // if (d > 0) { | ||
| // y--; | ||
| // d += 4 * (x - y) + 10; | ||
| // } else { | ||
| // d += 4 * x + 6; | ||
| // } | ||
| //} | ||
| if (d <= 0) d += ++x; | ||
| else d -= --y; | ||
| } | ||
| break; | ||
| } | ||
| case M12_pCorner: | ||
| for (int x = 0; x <= i; x++) setPixelColorXY(x, i, col); // note: <= to include i=0. Relies on overflow check in sPC() | ||
| for (int y = 0; y < i; y++) setPixelColorXY(i, y, col); | ||
|
|
@@ -947,9 +936,16 @@ uint32_t WLED_O2_ATTR Segment::getPixelColor(int i) const | |
| else { y = vH - i - 1; }; | ||
| break; | ||
| case M12_pArc: | ||
| if (i > vW && i > vH) { | ||
| x = y = sqrt32_bw(i*i/2); | ||
| break; // use diagonal | ||
| if (i >= vW && i >= vH) { // Barrera's circle algorithm | ||
blazoncek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| int x2 = 0, y2 = i, d = -(i >> 1); | ||
| int validCount = 0; // return 2nd non mirrored pixel if available | ||
| while (x2 <= y2 && validCount < 2) { | ||
| if (y2 < vH && x2 < vW) {x = x2, y = y2; validCount++;} | ||
| else if (y2 < vW && x2 < vH) {x = y2, y = x2; validCount++;} | ||
|
|
||
| if (d <= 0) d += ++x2; else d -= --y2; | ||
| } | ||
| break; | ||
|
Comment on lines
942
to
952
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix getPixelColor guard for pArc (breaks mapping)
Please drop that guard (or at least require only - case M12_pArc:
- if (i >= vW && i >= vH) {
+ case M12_pArc: {
+ int hitCount = 0;
+ int xSel = 0, ySel = 0;
int x2 = 0, y2 = i, d = -(i >> 1);
- int validCount = 0;
- while (x2 <= y2 && validCount < 2) {
- if (y2 < vH && x2 < vW) {x = x2, y = y2; validCount++;}
- else if (y2 < vW && x2 < vH) {x = y2, y = x2; validCount++;}
+ while (x2 <= y2 && hitCount < 2) {
+ if (y2 < vH && x2 < vW) { xSel = x2; ySel = y2; hitCount++; }
+ else if (y2 < vW && x2 < vH) { xSel = y2; ySel = x2; hitCount++; }
if (d <= 0) d += ++x2; else d -= --y2;
}
- break;
- }
+ if (hitCount) { x = xSel; y = ySel; break; }
+ // otherwise fall through
+ }That keeps read/write symmetry for all radii while still falling back when nothing lands inside bounds. 🤖 Prompt for AI Agents |
||
| } | ||
| // otherwise fallthrough | ||
| case M12_pCorner: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.