Browse Source

Added some assertions when the input to a NormalisableRange conversion function is outside of the expected range

tags/2021-05-28
Tom Poole 7 years ago
parent
commit
f5174e340e
1 changed files with 15 additions and 2 deletions
  1. +15
    -2
      modules/juce_core/maths/juce_NormalisableRange.h

+ 15
- 2
modules/juce_core/maths/juce_NormalisableRange.h View File

@@ -143,9 +143,9 @@ public:
ValueType convertTo0to1 (ValueType v) const noexcept
{
if (convertTo0To1Function != nullptr)
return convertTo0To1Function (start, end, v);
return clampTo0To1 (convertTo0To1Function (start, end, v));
auto proportion = (v - start) / (end - start);
auto proportion = clampTo0To1 ((v - start) / (end - start));
if (skew == static_cast<ValueType> (1))
return proportion;
@@ -166,6 +166,8 @@ public:
*/
ValueType convertFrom0to1 (ValueType proportion) const noexcept
{
proportion = clampTo0To1 (proportion);
if (convertFrom0To1Function != nullptr)
return convertFrom0To1Function (start, end, proportion);
@@ -261,6 +263,17 @@ private:
jassert (skew > ValueType());
}
static ValueType clampTo0To1 (ValueType value)
{
auto clampedValue = jlimit (static_cast<ValueType> (0), static_cast<ValueType> (1), value);
// If you his this assertion then either your normalisation function is not working
// correctly or your input is out of the expected bounds.
jassert (clampedValue == value);
return clampedValue;
}
typedef std::function<ValueType(ValueType, ValueType, ValueType)> ConverstionFunction;
ConverstionFunction convertFrom0To1Function = {},
convertTo0To1Function = {},


Loading…
Cancel
Save