From 91d4ba9891bc95d3fd68c89818101e8dbb508acf Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 23 Feb 2017 09:15:46 +0000 Subject: [PATCH] Added method NormalisableRange::setSkewForCentre() --- .../juce_core/maths/juce_NormalisableRange.h | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/juce_core/maths/juce_NormalisableRange.h b/modules/juce_core/maths/juce_NormalisableRange.h index a412c186fe..bbf845f2bc 100644 --- a/modules/juce_core/maths/juce_NormalisableRange.h +++ b/modules/juce_core/maths/juce_NormalisableRange.h @@ -46,7 +46,10 @@ class NormalisableRange { public: /** Creates a continuous range that performs a dummy mapping. */ - NormalisableRange() noexcept : start(), end (1), interval(), skew (static_cast (1)), symmetricSkew (false) {} + NormalisableRange() noexcept + : start(), end (1), interval(), + skew (static_cast (1)), symmetricSkew (false) + {} /** Creates a copy of another range. */ NormalisableRange (const NormalisableRange& other) noexcept @@ -131,7 +134,7 @@ public: if (skew != static_cast (1) && proportion > ValueType()) proportion = std::exp (std::log (proportion) / skew); - return start + (end - start) * proportion; + return start + (end - start) * proportion; } ValueType distanceFromMiddle = static_cast (2) * proportion - static_cast (1); @@ -162,6 +165,21 @@ public: Range getRange() const noexcept { return Range (start, end); } + /** Given a value which is between the start and end points, this sets the skew + such that convertFrom0to1 (0.5) will return this value. + @param centrePointValue this must be greater than the start of the range and less than the end. + */ + void setSkewForCentre (ValueType centrePointValue) noexcept + { + jassert (centrePointValue > start); + jassert (centrePointValue < end); + + symmetricSkew = false; + skew = std::log (static_cast (0.5)) + / std::log ((centrePointValue - start) / (end - start)); + checkInvariants(); + } + /** The start of the non-normalised range. */ ValueType start;