-
Notifications
You must be signed in to change notification settings - Fork 226
fix: prevent NaN in transform calculations when scale is 0 #1971
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
Conversation
- Add MIN_SCALE constant to avoid zero scaling - Update scale transform functions to enforce minimum scale value - Add test case for scale(0) transform - Add demo example with scale(0) transform
🦋 Changeset detectedLatest commit: 32e4c56 The changes in this PR will be included in the next version bump. This PR includes changesets to release 47 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Summary of Changes
Hello @wang1212, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request resolves a critical bug where applying a zero scale factor to an element's transform could lead to NaN values in subsequent matrix calculations, causing rendering issues. My solution introduces a small minimum threshold for all scaling operations, ensuring that the transformation matrix remains reversible and calculations always yield finite numbers. This change includes updated test coverage to validate the fix.
Highlights
- Bug Fix: NaN Prevention in Transforms: I've addressed an issue where
NaNvalues could appear in transform calculations, specifically when a scale factor of0was applied. This was due to the resulting transformation matrix becoming irreversible. - Minimum Scale Threshold: To prevent irreversible matrices and
NaNs, I've introduced aMIN_SCALEconstant (0.000001). All scaling operations (e.g.,scale,scaleX,scaleY,scale3d) now ensure that the scale value is at least this minimum threshold, effectively preventing it from becoming exactly zero. - New Test Cases: I've added a new unit test in
__tests__/unit/css/properties/transform.spec.tsto specifically verify that applyingscale(0)results in finite bounds (noNaNs). A corresponding demo case was also added in__tests__/demos/2d/transform.ts. - Changelog Entry: A new changeset file (
.changeset/all-dots-check.md) has been added to document this bug fix for the@antv/g-litepackage.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a minimum scale value to prevent NaN values in transform calculations when scale is 0. The added tests validate the fix. Suggestions have been provided to improve code maintainability by reducing duplication and cleaning up the test case.
- Add clampScale helper function to avoid code duplication - Replace repeated Math.max(item, MIN_SCALE) calls with clampScale - Maintain same behavior while improving code maintainability
* fix: prevent NaN in transform calculations when scale is 0 - Add MIN_SCALE constant to avoid zero scaling - Update scale transform functions to enforce minimum scale value - Add test case for scale(0) transform - Add demo example with scale(0) transform * chore: add changeset * refactor: extract scale clamping logic into reusable function - Add clampScale helper function to avoid code duplication - Replace repeated Math.max(item, MIN_SCALE) calls with clampScale - Maintain same behavior while improving code maintainability
* fix: prevent NaN in transform calculations when scale is 0 (#1971) * fix: prevent NaN in transform calculations when scale is 0 - Add MIN_SCALE constant to avoid zero scaling - Update scale transform functions to enforce minimum scale value - Add test case for scale(0) transform - Add demo example with scale(0) transform * chore: add changeset * refactor: extract scale clamping logic into reusable function - Add clampScale helper function to avoid code duplication - Replace repeated Math.max(item, MIN_SCALE) calls with clampScale - Maintain same behavior while improving code maintainability * chore: add changeset * perf: use charWidthCache to improve performance by 1.5% (#1978) * perf: 避免重复dirty父级元素提升2%性能 * perf: accept gemini review Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * refactor: 修复eslint * perf: use charWidthCache to improve performance by 1.5% * refactor: 修复评审意见 * refactor: 修复评审意见 * refactor: 使用LRU * refactor: 使用LRU * chore: add changeset --------- Co-authored-by: huiyu.zjt <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: wang1212 <[email protected]> * revert: fix element attribute update exception #1968 * chore(release): bump version (#1977) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: huiyu.zjt <[email protected]> Co-authored-by: huiyu.zjt <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
🤔 This is a ...
🔗 Related issue link
fixed #1953
💡 Background and solution
see #1953 (comment)
To ensure that the matrix is always reversible, the determinant must not be
0, and the diagonal component of the matrix, namelyscale, must also not be0. Therefore, we can set a minimum threshold. When the scale is small enough, the visual element will be invisible and will not affect the existing product visual effects. It may affect the test snapshot, so just update the test benchmark.📝 Changelog
☑️ Self Check before Merge