eis/TestProject/RNG/model/LinearModel.h
Huamonarch e4233cc23d fix: add period_ms to linear and drift models to prevent unbounded divergence
Without period, y=k*t+b and y=base+drift_rate*t grow infinitely, which is
unrealistic for industrial simulation. period_ms makes t wrap modulo the period,
producing sawtooth patterns that simulate per-cycle behavior (e.g. tension build-up
per coil, sensor drift per shift).
2026-05-13 16:34:00 +08:00

17 lines
450 B
C

#pragma once
#include <TestProject/RNG/model/IModel.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
struct LinearModel : IModel {
float k, b;
size_t period_ticks;
LinearModel(const json& params, float defaultVal)
: k(params.value("k", 0.0f)), b(defaultVal)
, period_ticks(params.value("period_ms", 0) / 20) {}
float evaluate(size_t t) override {
if (period_ticks > 0) t %= period_ticks;
return k * t + b;
}
};