Skip to content

Commit

Permalink
feat: target offset 限制矩形尺寸
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Jan 17, 2025
1 parent 34ca862 commit ea66ca1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions source/MaaFramework/Task/Component/Actuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ cv::Rect Actuator::get_target_rect(const MAA_RES_NS::Action::Target target, cons
LogError << "tasker is null";
return {};
}
if (!tasker_->controller()) {
LogError << "controller is null";
return {};
}

using namespace MAA_RES_NS::Action;

Expand All @@ -295,10 +299,13 @@ cv::Rect Actuator::get_target_rect(const MAA_RES_NS::Action::Target target, cons
return {};
}

return cv::Rect { raw.x + target.offset.x,
raw.y + target.offset.y,
raw.width + target.offset.width,
raw.height + target.offset.height };
auto image = controller()->cached_image();
int x = std::clamp(raw.x, 0, image.cols);
int y = std::clamp(raw.y, 0, image.rows);
int width = std::clamp(raw.width, 0, image.cols - x);
int height = std::clamp(raw.height, 0, image.rows - y);

return cv::Rect(x, y, width, height);
}

MAA_CTRL_NS::ControllerAgent* Actuator::controller()
Expand Down

0 comments on commit ea66ca1

Please sign in to comment.