1
0
Fork 0

[JSBSim] Bug fixes

* Functions <random/> and <urandom/> are no longer considered constant.
* <clipto type="cyclic"> now clips negatives values correctly.
This commit is contained in:
Bertrand Coconnier 2019-10-13 14:18:09 +02:00
parent 22de9d30b5
commit 73b7e94358
2 changed files with 18 additions and 3 deletions

View file

@ -802,6 +802,9 @@ FGFunction::~FGFunction()
bool FGFunction::IsConstant(void) const
{
// Functions without parameters are assumed to be non-const
if (Parameters.empty()) return false;
for (auto p: Parameters) {
if (!p->IsConstant())
return false;

View file

@ -227,13 +227,25 @@ void FGFCSComponent::Clip(void)
{
if (clip) {
double vmin = ClipMin->GetValue();
if (cyclic_clip) {
double vmax = ClipMax->GetValue();
double range = vmax - vmin;
if (range < 0.0) {
cerr << "Trying to clip with a max value " << ClipMax->GetName()
<< " lower than the min value " << ClipMin->GetName()
<< endl;
throw("JSBSim aborts");
return;
}
if (cyclic_clip && range != 0.0) {
double value = Output - vmin;
double range = ClipMax->GetValue() - vmin;
Output = fmod(value, range) + vmin;
if (Output < vmin)
Output += range;
}
else
Output = Constrain(vmin, Output, ClipMax->GetValue());
Output = Constrain(vmin, Output, vmax);
}
}