-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Pinwheel Rework #4551
base: main
Are you sure you want to change the base?
Pinwheel Rework #4551
Conversation
Optimized pinwheel algorithm. Math and memory optimizations by @DedeHai
WalkthroughThe pull request refactors the pinwheel effect logic within the WS2812FX implementation. It removes several constants previously used for effect dimensions and angles, updates the fixed scale constant from 512 to 16384, and introduces a new helper function to compute pinwheel parameters using Bresenham’s algorithm. Additionally, the pixel color setting method is updated to incorporate the new logic. Changes
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
wled00/FX_fcn.cpp (2)
689-702
: Validate scale-safety for angles and expansions.The calculations in
setPinwheelParameters()
rely on(i + k) * baseAngle
. Ifi
becomes unexpectedly large, there could be potential overflow when multiplied bybaseAngle
. Consider clamping or validating the range ofi
to ensure it cannot exceed the pinwheel length.
836-930
: Potential stack usage concern and index checks.
uint16_t lineCoords[2][maxLineLength]
; sincemaxLineLength
ismax(vW, vH) + 2
, large 2D matrices could pressure stack memory. A comment or safeguard to prevent overly large arrays might be warranted.- At lines 864-866,
closestEdgeIdx = min(closestEdgeIdx, idx-2);
relies on an incrementedidx
to be at least 2 after the first iteration. This logic is sound given the immediate increment, but consider an extra defensive check if future changes alter that loop’s indexing mechanism.- At line 900, there is a note “//!! should be long line idx!” clarifying which index to read from. Ensure that the commented hint matches intended usage (using
longLineIdx
consistently) or consider a minor refactor for clarity to avoid confusion.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
wled00/FX_fcn.cpp
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: wled_build / Build Enviornments (esp32s3_4M_qspi)
- GitHub Check: wled_build / Build Enviornments (esp32s3dev_8MB_opi)
- GitHub Check: wled_build / Build Enviornments (esp32s3dev_16MB_opi)
- GitHub Check: wled_build / Build Enviornments (lolin_s2_mini)
- GitHub Check: wled_build / Build Enviornments (esp32_eth)
- GitHub Check: wled_build / Build Enviornments (esp8266_2m)
🔇 Additional comments (3)
wled00/FX_fcn.cpp (3)
683-684
: Good introduction of a higher fixed-point scale.The larger
Fixed_Scale
value (16384) increases precision in trigonometric calculations for the pinwheel effect. This should reduce rounding artifacts for 2D transformations.
685-688
: Ensure consistent usage of the pinwheel step size.The function
getPinwheelLength()
always returns a multiple of 8. While this helps avoid over-drawing, ensure all code paths using pinwheel rays respect this multiple-of-8 strategy and do not silently assume a different step geometry.
1064-1077
: Double-check edge tracing in getPixelColor.Using
setPinwheelParameters(i, vW, vH, x, y, cosVal, sinVal, true)
to rotate half a ray width is a clever approach. However, the while loop at lines 1069-1071 stops once any edge is reached. Confirm that cases wherevW
orvH
is 1 or very small matrices still produce an expected result, as the logic could exit immediately with minimal coverage.
Previous discussions here: #4185
Pinwheel algorithm optimized. Math and memory optimizations by @DedeHai
May still have a few quirks in untested matrix sizes / effects.
Summary by CodeRabbit