feat: 新增 Radiation 排序方式及可选 center 参数#1321
Open
1204244136 wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了两个问题,并给出了一些整体性的反馈:
- 在
sort_by_radiation_中,你在排序比较器里每次比较都调用了std::hypot;你可以通过比较平方距离(避免开方)来降低开销,或者在排序前为每个结果预先计算一次距离。
给 AI 代理的提示
Please address the comments from this code review:
## Overall Comments
- In `sort_by_radiation_`, you’re calling `std::hypot` inside the sort comparator for every comparison; you could reduce overhead by comparing squared distances instead (avoiding the sqrt) or by precomputing each result’s distance once before sorting.
## Individual Comments
### Comment 1
<location path="source/MaaWin32ControlUnit/Input/SeizeInput.cpp" line_range="240" />
<code_context>
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = static_cast<WORD>(key);
+ inputs[0].ki.wScan = static_cast<WORD>(MapVirtualKeyW(static_cast<UINT>(key), MAPVK_VK_TO_VSC));
SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 请考虑为 wScan 使用 MAPVK_VK_TO_VSC_EX,或加入对扩展键的专门处理。
使用 MAPVK_VK_TO_VSC 的 MapVirtualKeyW 在处理扩展键时(例如方向键、右 Ctrl/Alt)可能返回错误的扫描码。由于现在显式设置了 wScan,建议使用 MAPVK_VK_TO_VSC_EX,或者为扩展键添加条件分支,以确保在不同键盘布局下都有正确行为。
</issue_to_address>
### Comment 2
<location path="source/binding/NodeJS/src/apis/pipeline.d.ts" line_range="52" />
<code_context>
index?: number
method?: 10001 | 3 | 5
green_mask?: boolean
+ center?: [number, number]
},
'template',
</code_context>
<issue_to_address>
**suggestion:** 为 center 元组引入一个可复用的 Point 类型别名,以避免重复。
`center` 的 `[number, number]` 元组在多个识别类型中出现。请引入一个共享别名,例如 `type Point = [number, number];`,并使用 `center?: Point`,以提升可维护性和可读性,尤其是在这一结构在其他地方也会复用的情况下。
建议实现如下:
```typescript
green_mask?: boolean
center?: Point
},
'template',
Mode
green_mask?: boolean
detector?: 'SIFT' | 'KAZE' | 'AKAZE' | 'BRISK' | 'ORB'
ratio?: number
center?: Point
},
'template',
Mode
order_by?: OrderByMap['ColorMatch']
index?: number
```
1. 在这个声明文件中引入一个可复用的元组别名,例如放在其他共享类型别名附近:
`type Point = [number, number];`
2. 确保本文件中所有表示二维点的 `[number, number]` 都更新为使用新的 `Point` 别名,以保持一致性。
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- In
sort_by_radiation_, you’re callingstd::hypotinside the sort comparator for every comparison; you could reduce overhead by comparing squared distances instead (avoiding the sqrt) or by precomputing each result’s distance once before sorting.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `sort_by_radiation_`, you’re calling `std::hypot` inside the sort comparator for every comparison; you could reduce overhead by comparing squared distances instead (avoiding the sqrt) or by precomputing each result’s distance once before sorting.
## Individual Comments
### Comment 1
<location path="source/MaaWin32ControlUnit/Input/SeizeInput.cpp" line_range="240" />
<code_context>
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = static_cast<WORD>(key);
+ inputs[0].ki.wScan = static_cast<WORD>(MapVirtualKeyW(static_cast<UINT>(key), MAPVK_VK_TO_VSC));
SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider MAPVK_VK_TO_VSC_EX or extended-key handling for wScan.
MapVirtualKeyW with MAPVK_VK_TO_VSC can return incorrect scan codes for extended keys (e.g., arrows, right Ctrl/Alt). Since wScan is now set explicitly, consider using MAPVK_VK_TO_VSC_EX or a conditional path for extended keys to ensure correct behavior across keyboard layouts.
</issue_to_address>
### Comment 2
<location path="source/binding/NodeJS/src/apis/pipeline.d.ts" line_range="52" />
<code_context>
index?: number
method?: 10001 | 3 | 5
green_mask?: boolean
+ center?: [number, number]
},
'template',
</code_context>
<issue_to_address>
**suggestion:** Introduce a reusable Point type alias for the center tuple to avoid duplication.
The `[number, number]` tuple for `center` appears in multiple recognition types. Please introduce a shared alias, e.g. `type Point = [number, number];`, and use `center?: Point` for better maintainability and clarity, especially if this shape is reused elsewhere.
Suggested implementation:
```typescript
green_mask?: boolean
center?: Point
},
'template',
Mode
green_mask?: boolean
detector?: 'SIFT' | 'KAZE' | 'AKAZE' | 'BRISK' | 'ORB'
ratio?: number
center?: Point
},
'template',
Mode
order_by?: OrderByMap['ColorMatch']
index?: number
```
1. Introduce a reusable tuple alias in this declaration file, e.g. near the other shared type aliases:
`type Point = [number, number];`
2. Ensure all other occurrences of `[number, number]` representing a 2D point in this file are updated to use the new `Point` alias for consistency.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
新增 order_by "Radiation" 排序方式,按识别结果中心点到参考中心的欧氏距离 升序排列。可通过可选的 center 参数 [x, y] 指定参考中心,未指定时自动使用 所有结果包围框的中心。 涉及修改: - VisionTypes.h: 6 个 param struct 新增 cv::Point center 字段 - VisionUtils.hpp: 新增 sort_by_radiation_ 排序函数 - PipelineParser.cpp: 新增 Radiation 解析及 center 字段读取 - PipelineDumper.cpp: 新增 Radiation 序列化及 center 字段输出 - PipelineTypesV2.h: 6 个 JStruct 新增 center 字段 - 6 个 Vision .cpp: sort_ switch 新增 Radiation 分支 - docs (zh_cn/en_us): 新增 Radiation 排序说明及 center 字段文档 - pipeline.d.ts: NodeJS 类型定义新增 Radiation 和 center 已知风险:center 使用 cv::Point(-1, -1) 作为"未指定"的哨兵值。 项目自 v5.6 起 roi/target 的负坐标有"从边缘反向计算"的语义, center 作为屏幕坐标理论上应遵循同一约定,两者存在潜在冲突。 实际风险可忽略:center 是排序参考点,用户将其设为负坐标(屏幕 边缘外)无实际意义。若未来确需支持,可迁移至 std::optional 方案。
d90ab70 to
7c9c6f5
Compare
Member
|
🤖 center 用 |
MistEO
reviewed
May 15, 2026
Member
MistEO
left a comment
There was a problem hiding this comment.
🤖 optional 化 center 👍。按仓库 checklist 还差 tools/pipeline.schema.json 和 Python maa/pipeline.py 里各 J* 的 center(以及 schema 里 order_by 枚举补上 Radiation),补完我再扫一遍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
在各类视觉识别流水线中新增一种带可选中心坐标的 Radiation 结果排序模式,通过 NodeJS 绑定和文档对其进行暴露,并改进 Windows 键盘输入事件的扫描码处理。
New Features:
order_by模式,使所有相关视觉识别器可以根据距离参考中心点的远近对识别结果进行排序。center参数,用于配置 Radiation 排序所使用的参考点。Bug Fixes:
Enhancements:
center参数。center选项的说明。Original summary in English
Summary by Sourcery
Add a new Radiation result-sorting mode with optional center coordinates across vision recognition pipelines, expose it through NodeJS bindings and docs, and improve Windows keyboard input event scan code handling.
New Features:
Bug Fixes:
Enhancements: