Skip to content

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

Open
ocsin1 wants to merge 1 commit into
MaaXYZ:mainfrom
ocsin1:fix/get_target_rect
Open

fix(Task): get_target_rect 对所有 target 类型处理 offset 引入的负宽高#1373
ocsin1 wants to merge 1 commit 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 裁剪。(因为这样是原逻辑,而且更有用)

Summary by Sourcery

错误修复:

  • 修复 get_target_rect,使其在出现导致宽度/高度为负的偏移量时,像 ROI 一样进行归一化处理,而不是直接钳制为零,从而防止出现空矩形以及在所有目标类型上发生的“failed to get target rect”错误。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fix get_target_rect so that offsets producing negative width/height are normalized ROI-style instead of clamped to zero, preventing empty rectangles and “failed to get target rect” errors across all target types.

此前 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.

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.

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

1 participant