Skip to content

fix(Task): get_target_rect 对所有 target 类型处理 offset 引入的负宽高 - #1373

Open
ocsin1 wants to merge 2 commits into
MaaXYZ:mainfrom
ocsin1:fix/get_target_rect
Open

fix(Task): get_target_rect 对所有 target 类型处理 offset 引入的负宽高#1373
ocsin1 wants to merge 2 commits into
MaaXYZ:mainfrom
ocsin1:fix/get_target_rect

Conversation

@ocsin1

@ocsin1 ocsin1 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

此前 target_offset 的负宽高仅 Region 类型通过 normalize_rect 间接 支持。Self/PreTask/Anchor 类型的 offset 若含负宽高,会直接被
std::clamp 变为 0,导致 cv::Rect::empty() 命中,动作报 "failed to get target rect" 错误。

示例:

{
    "1": {
        "roi": [
            790,
            308,
            154,
            18
        ],
        "action": "Click",// 这样会报错
        "target_offset": [
            0,
            -50,
            0,
            -30
        ]
    },
    "2": {
        "roi": [
            790,
            258,
            154,
            -12
        ] // 直接点击偏移后结果这样不会
    }
}

对 offset 应用后的负宽高按 ROI 语义(取绝对值并反向调整 x/y)处理,
该逻辑对所有 target 类型生效。不直接调 normalize_rect,因为其负 x/y
的"从边缘算起"语义对 offset 不适用,x/y 仍由 clamp 裁剪。(因为这样是原逻辑,而且更有用)

Sourcery 总结

修复目标矩形计算问题,确保带有负尺寸的偏移量能够在所有目标类型中生成有效且位置正确的区域。

错误修复:

  • 处理所有目标类型中由目标偏移引入的负宽度和负高度,避免将有效的调整后区域误判为空矩形。

增强功能:

  • 保留 ROI 语义:在应用图像边界裁剪之前,反转受影响矩形的位置,并取其尺寸的绝对值。
Original summary in English

Sourcery 总结

修复目标矩形计算问题,确保对于所有目标类型,负尺寸偏移都能生成有效且位置正确的区域。

错误修复:

  • 处理所有目标类型因目标偏移引入的负宽度和负高度,确保有效的调整后区域不再被视为空矩形。

改进:

  • 保留 ROI 语义:在应用图像边界裁剪之前,反转受影响矩形的位置并使用绝对尺寸。
Original summary in English

Summary by Sourcery

Fix target rectangle calculation so negative-size offsets produce valid, correctly positioned regions for all target types.

Bug Fixes:

  • Handle negative width and height introduced by target offsets for every target type so valid adjusted regions are no longer treated as empty rectangles.

Enhancements:

  • Preserve ROI semantics by reversing the affected rectangle position and using absolute dimensions before applying image-boundary clipping.
Original summary in English

此前 target_offset 的负宽高仅 Region 类型通过 normalize_rect 间接
支持。Self/PreTask/Anchor 类型的 offset 若含负宽高,会直接被
std::clamp 夹为 0,导致 cv::Rect::empty() 命中,动作报 "failed to get
target rect" 错误。

对 offset 应用后的负宽高按 ROI 语义(取绝对值并反向调整 x/y)处理,
该逻辑对所有 target 类型生效。不直接调 normalize_rect,因为其负 x/y
的"从边缘算起"语义对 offset 不适用,x/y 仍由 clamp 裁剪。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - 我已经审查了你的修改,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread source/MaaFramework/Task/Component/ActionHelper.cpp Outdated
@ocsin1
ocsin1 marked this pull request as draft September 5, 2026 09:36
@ocsin1
ocsin1 marked this pull request as ready for review September 5, 2026 12:51

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

嘿——我已经审阅了你的更改,看起来很棒!


Sourcery 对开源项目免费——如果你喜欢我们的评审,欢迎考虑分享 ✨
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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.

[基质刷取]在按钮可见的情况下仍然点击失败

2 participants