eis/eqpalg/utility/bound_checker.cpp
Huamonarch b9cf5f4e9e refactor: 提取 BoundChecker 上下限检测组件
从 ExpBase 提取 detect_up_down() 逻辑和哨兵值处理至独立的 BoundChecker 类。
将 DetectMode 从 struct 升级为 enum class。
2026-05-15 14:09:56 +08:00

35 lines
1.1 KiB
C++

// eqpalg/utility/bound_checker.cpp
#include <eqpalg/utility/bound_checker.h>
void BoundChecker::setLimits(double down, double up) {
limit_down_ = down;
limit_up_ = up;
// 哨兵值推导检测模式(与 ExpBase::reload_config_up_down 逻辑一致)
int idown = static_cast<int>(down);
int iup = static_cast<int>(up);
if (idown == -32768 && iup != idown) {
detect_mode_ = DetectMode::OnlyRight; // 仅右边界
} else if ((iup == -32768 || iup == 32768 || iup == 32767) && iup != idown) {
detect_mode_ = DetectMode::OnlyLeft; // 仅左边界
} else if (iup == -32768 && iup == idown) {
detect_mode_ = DetectMode::ErrorMode; // 配置错误
} else {
detect_mode_ = DetectMode::Default; // 双侧
}
}
bool BoundChecker::isOutOfBounds(double value) const {
switch (detect_mode_) {
case DetectMode::Default:
return value < limit_down_ || value > limit_up_;
case DetectMode::OnlyLeft:
return value < limit_down_;
case DetectMode::OnlyRight:
return value > limit_up_;
default:
return false;
}
}