Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@wang1212
Copy link
Member

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / Document optimization
  • TypeScript definition update
  • Refactoring
  • Performance improvement
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 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, namely scale, must also not be 0. 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

Language Changelog
🇺🇸 English fix: prevent NaN in transform calculations when scale is 0
🇨🇳 Chinese fix: 当 scale 为 0 时,防止在变换计算中出现 NaN

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

wang1212 added 2 commits July 21, 2025 14:15
- 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-bot
Copy link

changeset-bot bot commented Jul 21, 2025

🦋 Changeset detected

Latest commit: 32e4c56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 47 packages
Name Type
@antv/g-lite Patch
@antv/g-camera-api Patch
@antv/g-canvas Patch
@antv/g-canvaskit Patch
@antv/g-components Patch
@antv/g-dom-mutation-observer-api Patch
@antv/g-gesture Patch
@antv/g-image-exporter Patch
@antv/g-lottie-player Patch
@antv/g-mobile-canvas-element Patch
@antv/g-mobile-canvas Patch
@antv/g-mobile-svg Patch
@antv/g-mobile-webgl Patch
@antv/g-pattern Patch
@antv/g-plugin-3d Patch
@antv/g-plugin-a11y Patch
@antv/g-plugin-annotation Patch
@antv/g-plugin-box2d Patch
@antv/g-plugin-canvas-path-generator Patch
@antv/g-plugin-canvas-picker Patch
@antv/g-plugin-canvas-renderer Patch
@antv/g-plugin-canvaskit-renderer Patch
@antv/g-plugin-control Patch
@antv/g-plugin-css-select Patch
@antv/g-plugin-device-renderer Patch
@antv/g-plugin-dom-interaction Patch
@antv/g-plugin-dragndrop Patch
@antv/g-plugin-gesture Patch
@antv/g-plugin-html-renderer Patch
@antv/g-plugin-image-loader Patch
@antv/g-plugin-matterjs Patch
@antv/g-plugin-mobile-interaction Patch
@antv/g-plugin-physx Patch
@antv/g-plugin-rough-canvas-renderer Patch
@antv/g-plugin-rough-svg-renderer Patch
@antv/g-plugin-svg-picker Patch
@antv/g-plugin-svg-renderer Patch
@antv/g-plugin-yoga Patch
@antv/g-plugin-zdog-canvas-renderer Patch
@antv/g-plugin-zdog-svg-renderer Patch
@antv/g-svg Patch
@antv/g-web-animations-api Patch
@antv/g-web-components Patch
@antv/g-webgl Patch
@antv/g-webgpu Patch
@antv/g Patch
@antv/react-g Patch

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

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 NaN values could appear in transform calculations, specifically when a scale factor of 0 was applied. This was due to the resulting transformation matrix becoming irreversible.
  • Minimum Scale Threshold: To prevent irreversible matrices and NaNs, I've introduced a MIN_SCALE constant (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.ts to specifically verify that applying scale(0) results in finite bounds (no NaNs). 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-lite package.
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

  1. 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.

@wang1212 wang1212 requested a review from Aarebecca July 21, 2025 06:27
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@wang1212 wang1212 requested review from hustcc, lxfu1 and lzxue July 21, 2025 06:30
- 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
@wang1212 wang1212 merged commit a9dad22 into release Jul 21, 2025
2 checks passed
@wang1212 wang1212 deleted the fix-1953 branch July 21, 2025 11:04
wang1212 added a commit that referenced this pull request Jul 21, 2025
* 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
wang1212 added a commit that referenced this pull request Jul 30, 2025
* 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>
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.

3 participants