Skip to content

refactor: enhance vector operations robustness#7581

Merged
Aarebecca merged 8 commits intoantvis:v5from
typenoob:improve-vector
Feb 11, 2026
Merged

refactor: enhance vector operations robustness#7581
Aarebecca merged 8 commits intoantvis:v5from
typenoob:improve-vector

Conversation

@typenoob
Copy link
Contributor

@typenoob typenoob commented Jan 9, 2026

总结:

  • 添加padVectors函数用于填充两个向量至相同维度
  • 在对两个向量执行add substract multiply divide dot distance manhattanDistance angle运算前应用padVectors
  • 添加对二维向量与三维向量之间进行运算的测试用例

close #7580

yutao chen added 2 commits January 9, 2026 15:45
	modified:   packages/g6/src/utils/vector.ts
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @typenoob, 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!

此拉取请求旨在增强向量操作的鲁棒性,使其能够更灵活地处理不同维度的向量。通过引入一个维度填充机制,确保在执行加、减、乘、除、点积、距离计算和角度计算等操作时,两个向量具有相同的维度,从而避免潜在的错误并提高代码的健壮性。

Highlights

  • 新增维度填充函数: 新增了 padVectors 函数,用于在执行向量操作前,将两个不同维度的向量填充至相同的维度,以确保操作的兼容性。
  • 增强向量操作的鲁棒性: 在 add, subtract, multiply, divide, dot, distance, manhattanDistance, angle 等核心向量操作函数中,集成了 padVectors 函数。这意味着这些操作现在能够自动处理和统一不同维度的向量,从而提高了代码的健壮性和容错性。
  • 扩展测试覆盖: 为验证维度填充逻辑的正确性,增加了针对不同维度向量进行操作的新测试用例,确保了新功能的行为符合预期。
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

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

这个 PR 旨在通过在向量操作前填充向量来增强其鲁棒性,这是一个很好的方向。我发现了一些可以改进的地方,包括一个潜在的严重 bug,一些代码可读性问题和小的错误。主要问题是在 divide 函数中可能出现除以零的情况,这会导致 NaN 结果,而测试期望的是 0。我还对 padVectors 函数提出了一些重构建议,以提高其可读性并修复一个小拼写错误。此外,还有一些可以使代码更清晰、更一致的小改动。另外,PR 的标题中有一个小拼写错误:refector 应该是 refactor

@typenoob typenoob changed the title [WIP] refector: enhance vector operations robustness [WIP] refactor: enhance vector operations robustness Jan 9, 2026
yutao chen added 3 commits January 9, 2026 16:33
	modified:   packages/g6/__tests__/unit/utils/vector.spec.ts
	modified:   packages/g6/src/elements/nodes/image.ts
const haloStyle = subStyleProps(this.getGraphicStyle(attributes), 'halo');
const haloLineWidth = Number(haloStyle.lineWidth);
const [width, height] = add(this.getSize(attributes), [haloLineWidth, haloLineWidth]);
const [width, height] = add(toVector2(this.getSize(attributes)), [haloLineWidth, haloLineWidth]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我搜索了一下getSize(attributes),发现全都是为了获取width或height。
为什么要将它的返回值设置为三维类型呢? cc @yvonneyx

export function parseSize(size: Size = 0): STDSize {
if (typeof size === 'number') return [size, size, size] as STDSize;
const [x, y = x, z = x] = size;
return [x, y, z];
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为会涉及 3D 图可视化,此时节点将是3维图形

@typenoob typenoob changed the title [WIP] refactor: enhance vector operations robustness refactor: enhance vector operations robustness Jan 9, 2026
@typenoob typenoob closed this Jan 9, 2026
@typenoob typenoob reopened this Jan 9, 2026
@typenoob
Copy link
Contributor Author

typenoob commented Jan 9, 2026

本地运行npm run test layouts/dagre是PASS的
不知道这个CI为什么不通过 也不知道除了提交怎么能重新运行?

@Aarebecca
Copy link
Contributor

@typenoob 感谢贡献,我会尽快处理该问题

@Aarebecca
Copy link
Contributor

/gemini review

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

本次 PR 通过引入 padVectors 函数,优雅地处理了不同维度向量(2D与3D)间的运算,显著增强了向量操作的鲁棒性。相关函数如 add, subtract, multiply 等都因此受益,代码健壮性得到提升。新增的测试用例也很好地覆盖了这些边界情况。整体来看,这是一次高质量的重构。我提出了一些小的建议,旨在进一步提升代码的可读性和修复一个拼写错误。

typenoob and others added 2 commits February 11, 2026 16:03
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.95%. Comparing base (a36b53a) to head (0b8e469).

Files with missing lines Patch % Lines
packages/g6/src/utils/vector.ts 91.66% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##               v5    #7581      +/-   ##
==========================================
- Coverage   94.96%   94.95%   -0.02%     
==========================================
  Files         188      188              
  Lines        9982    10001      +19     
  Branches     2166     2169       +3     
==========================================
+ Hits         9479     9496      +17     
+ Misses        503      467      -36     
- Partials        0       38      +38     
Flag Coverage Δ
g6 94.95% <92.30%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/g6/src/elements/nodes/image.ts 86.04% <100.00%> (ø)
packages/g6/src/utils/vector.ts 97.29% <91.66%> (-2.71%) ⬇️

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Aarebecca Aarebecca merged commit b0e25b3 into antvis:v5 Feb 11, 2026
2 checks passed
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.

[Feat]: 优化向量计算时对维度不一致情况的处理

3 participants