Skip to content

Commit

Permalink
Custom and "Normal" value curves need to be scaled differently
Browse files Browse the repository at this point in the history
  • Loading branch information
computergeek1507 committed Dec 30, 2024
1 parent 9505a30 commit 7f6885b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions xLights/ValueCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,14 +2204,9 @@ void ValueCurve::ScaleAndOffsetValues(float scale, int offset)
if (offset == 0 && abs(scale - 1.0) < 0.0001) {
return;
}
float range = _max - _min;
if (std::abs(range) <= std::numeric_limits<float>::epsilon()) {
wxASSERT(false); // shouldn't be zero
return;
}
auto ScaleVal = [&](float val) -> float
{
const float valScaled = val * range;//0-255

auto ScaleVal = [&](float val, float range) -> float {
const float valScaled = val * range;
float newVal = (valScaled * (scale * _divisor)) + (offset * _divisor);
newVal = std::min(newVal, _max);
newVal = std::max(newVal, _min);
Expand All @@ -2220,9 +2215,14 @@ void ValueCurve::ScaleAndOffsetValues(float scale, int offset)

std::vector<int> parametersToScale;
if (_type == "Custom") {
//custom values are 0-1
// custom values are 0-1, so we need to scale them
float range = _max - _min;
if (std::abs(range) <= std::numeric_limits<float>::epsilon()) {
wxASSERT(false); // shouldn't be zero
return;
}
for (auto& it : _values) {
it.y = ScaleVal(it.y);
it.y = ScaleVal(it.y, range);
}
} else if (_type == "Flat") {
parametersToScale.push_back(1);
Expand All @@ -2244,20 +2244,20 @@ void ValueCurve::ScaleAndOffsetValues(float scale, int offset)
parametersToScale.push_back(3);
parametersToScale.push_back(4);
}

//_parameter1 are min to max
for (int param : parametersToScale) {
switch (param) {
case 1:
_parameter1 = ScaleVal(_parameter1);
_parameter1 = ScaleVal(_parameter1, 1.0F);
break;
case 2:
_parameter2 = ScaleVal(_parameter2);
_parameter2 = ScaleVal(_parameter2, 1.0F);
break;
case 3:
_parameter3 = ScaleVal(_parameter3);
_parameter3 = ScaleVal(_parameter3, 1.0F);
break;
case 4:
_parameter4 = ScaleVal(_parameter4);
_parameter4 = ScaleVal(_parameter4, 1.0F);
break;
}
}
Expand Down

0 comments on commit 7f6885b

Please sign in to comment.