diff options
-rw-r--r-- | src/powermap.cc | 14 | ||||
-rw-r--r-- | src/powermap.h | 3 |
2 files changed, 14 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)); +} diff --git a/src/powermap.h b/src/powermap.h index aa4cbfc..29a3c81 100644 --- a/src/powermap.h +++ b/src/powermap.h @@ -67,4 +67,7 @@ private: bool spline_needs_update; void updateSpline(); + Power clamp(Power in, Power min, Power max) const; + + const Power eps = 1e-3; }; |