Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Brandon502
Copy link
Contributor

@Brandon502 Brandon502 commented Feb 14, 2025

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

  • New Features
    • The LED pinwheel effect now delivers smoother, more precise animations for a consistently improved visual experience.
  • Refactor
    • Redesigned the calculation logic for effect positioning and step sizing, ensuring a more reliable and artifact-free display.

Optimized pinwheel algorithm. Math and memory optimizations by @DedeHai
Copy link

coderabbitai bot commented Feb 14, 2025

Walkthrough

The 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

File Change Summary
wled00/FX_fcn.cpp - Removed constants: Pinwheel_Steps_Small, Pinwheel_Size_Small, Pinwheel_Steps_Medium, Pinwheel_Size_Medium, Pinwheel_Steps_Big, Pinwheel_Size_Big, Pinwheel_Steps_XL, and associated Int_to_Rad* constants.
- Updated constant Fixed_Scale from 512 to 16384.
- Added new function setPinwheelParameters for calculating starting coordinates and angular steps using Bresenham's algorithm.
- Modified setPixelColor to integrate the new pinwheel logic.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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. If i becomes unexpectedly large, there could be potential overflow when multiplied by baseAngle. Consider clamping or validating the range of i to ensure it cannot exceed the pinwheel length.


836-930: Potential stack usage concern and index checks.

  1. uint16_t lineCoords[2][maxLineLength]; since maxLineLength is max(vW, vH) + 2, large 2D matrices could pressure stack memory. A comment or safeguard to prevent overly large arrays might be warranted.
  2. At lines 864-866, closestEdgeIdx = min(closestEdgeIdx, idx-2); relies on an incremented idx 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.
  3. 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

📥 Commits

Reviewing files that changed from the base of the PR and between a0c55c6 and e7e0eb0.

📒 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 where vW or vH is 1 or very small matrices still produce an expected result, as the logic could exit immediately with minimal coverage.

@DedeHai DedeHai self-requested a review February 14, 2025 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant