mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-18 00:54:19 +00:00
Added a couple of methods to Range.
This commit is contained in:
parent
b026fccb92
commit
9dcdea59a7
1 changed files with 27 additions and 0 deletions
|
|
@ -237,6 +237,13 @@ public:
|
|||
jmax (end, other.end));
|
||||
}
|
||||
|
||||
/** Returns the smallest range that contains both this one and the given value. */
|
||||
Range getUnionWith (const ValueType valueToInclude) const noexcept
|
||||
{
|
||||
return Range (jmin (valueToInclude, start),
|
||||
jmax (valueToInclude, end));
|
||||
}
|
||||
|
||||
/** Returns a given range, after moving it forwards or backwards to fit it
|
||||
within this range.
|
||||
|
||||
|
|
@ -255,6 +262,26 @@ public:
|
|||
: rangeToConstrain.movedToStartAt (jlimit (start, end - otherLen, rangeToConstrain.getStart()));
|
||||
}
|
||||
|
||||
/** Scans an array of values for its min and max, and returns these as a Range. */
|
||||
static Range findMinAndMax (const ValueType* values, int numValues) noexcept
|
||||
{
|
||||
if (numValues <= 0)
|
||||
return Range();
|
||||
|
||||
const ValueType first (*values++);
|
||||
Range r (first, first);
|
||||
|
||||
while (--numValues > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
|
||||
{
|
||||
const ValueType v (*values++);
|
||||
|
||||
if (r.end < v) r.end = v;
|
||||
if (v < r.start) r.start = v;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
ValueType start, end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue