diff options
author | André Nusser <andre.nusser@googlemail.com> | 2020-04-25 14:17:18 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2020-04-25 14:17:35 +0200 |
commit | 08489fe7085be47298e37adbb7787033a17b5905 (patch) | |
tree | eddae61eed88cd5043fbe05c4af86d235aa3b7d7 /src/powermap.cc | |
parent | 0ce90a85fa6d657ed423171bc94320a613b53e1e (diff) |
Enforce monotonicity in the powermap by the set functions.
Diffstat (limited to 'src/powermap.cc')
-rw-r--r-- | src/powermap.cc | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/powermap.cc b/src/powermap.cc index 52d52ef..ee2e67c 100644 --- a/src/powermap.cc +++ b/src/powermap.cc @@ -101,7 +101,8 @@ void Powermap::setFixed0(PowerPair new_value) { if (fixed[0] != new_value) { spline_needs_update = true; - this->fixed[0] = new_value; + fixed[0].in = clamp(new_value.in, eps, fixed[1].in-eps); + fixed[0].out = clamp(new_value.out, eps, fixed[1].out-eps); } } @@ -109,7 +110,8 @@ void Powermap::setFixed1(PowerPair new_value) { if (fixed[1] != new_value) { spline_needs_update = true; - this->fixed[1] = new_value; + fixed[1].in = clamp(new_value.in, fixed[0].in+eps, fixed[2].in-eps); + fixed[1].out = clamp(new_value.out, fixed[0].out+eps, fixed[2].out-eps); } } @@ -117,7 +119,8 @@ void Powermap::setFixed2(PowerPair new_value) { if (fixed[2] != new_value) { spline_needs_update = true; - this->fixed[2] = new_value; + fixed[2].in = clamp(new_value.in, fixed[1].in+eps, 1-eps); + fixed[2].out = clamp(new_value.out, fixed[1].out+eps, 1-eps); } } @@ -228,3 +231,8 @@ void Powermap::updateSpline() spline_needs_update = false; } + +Power Powermap::clamp(Power in, Power min, Power max) const +{ + return std::max(min, std::min(in, max)); +} |