Commit 30f512da authored by Nico Mack's avatar Nico Mack

Added code to constrain values to min and max

parent e7c2a68a
......@@ -189,8 +189,7 @@ public class NumericalVariable extends Variable<Double> {
if (this.valueRange != 0) {
double val = this.roundToPrecision(newValue);
val = Math.max(val, this.minValue);
val = Math.min(val, this.maxValue);
val = this.constrainValue(val);
normalized = (val - this.minValue) / this.valueRange;
}
return normalized;
......@@ -213,6 +212,15 @@ public class NumericalVariable extends Variable<Double> {
return Math.round(rawValue * this.roundingFactor) / this.roundingFactor;
}
// ---------------------------------------------------------------------------
private double constrainValue(double rawValue) {
double constrained = rawValue;
constrained = Math.max(constrained, this.minValue);
constrained = Math.min(constrained, this.maxValue);
return constrained;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
......@@ -308,7 +316,7 @@ public class NumericalVariable extends Variable<Double> {
this.normalizedValue = this.normalizeValue(val);
this.modified = ((newValue != null) && (!isEqual(val, this.value, this.epsilon)));
this.value = val;
this.value = this.constrainValue(val);
if (!this.notificationSuspended() && this.modified) {
this.notifyInputChangeListeners(new InputEvent(this));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment