eis/eqpalg/utility/bound_checker.cpp

35 lines
1.1 KiB
C++
Raw Permalink Normal View History

// 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;
}
}