38template <
typename ValueType>
44 JUCE_CONSTEXPR
Range() =
default;
47 JUCE_CONSTEXPR
Range (
const ValueType startValue,
const ValueType endValue) noexcept
48 : start (startValue), end (jmax (startValue, endValue))
59 JUCE_CONSTEXPR
static Range between (
const ValueType position1,
const ValueType position2)
noexcept
61 return position1 < position2 ?
Range (position1, position2)
62 :
Range (position2, position1);
68 jassert (length >= ValueType());
69 return Range (startValue, startValue + length);
75 return Range (start, start);
80 JUCE_CONSTEXPR
inline ValueType
getStart() const noexcept {
return start; }
83 JUCE_CONSTEXPR
inline ValueType
getLength() const noexcept {
return end - start; }
86 JUCE_CONSTEXPR
inline ValueType
getEnd() const noexcept {
return end; }
89 JUCE_CONSTEXPR
inline bool isEmpty() const noexcept {
return start == end; }
96 void setStart (
const ValueType newStart)
noexcept
109 return Range (newStart, jmax (newStart, end));
115 return Range (newStart, end + (newStart - start));
122 void setEnd (
const ValueType newEnd)
noexcept
135 return Range (jmin (start, newEnd), newEnd);
141 return Range (start + (newEnd - end), newEnd);
149 end = start + jmax (ValueType(), newLength);
157 return Range (start, start + newLength);
166 return Range (start - amount, end + amount);
173 start += amountToAdd;
181 start -= amountToSubtract;
182 end -= amountToSubtract;
191 return Range (start + amountToAdd, end + amountToAdd);
198 return Range (start - amountToSubtract, end - amountToSubtract);
201 JUCE_CONSTEXPR
bool operator== (
Range other)
const noexcept {
return start == other.start && end == other.end; }
202 JUCE_CONSTEXPR
bool operator!= (
Range other)
const noexcept {
return start != other.start || end != other.end; }
209 JUCE_CONSTEXPR
bool contains (
const ValueType position)
const noexcept
211 return start <= position && position < end;
215 ValueType
clipValue (
const ValueType value)
const noexcept
217 return jlimit (start, end, value);
223 return start <= other.start && end >= other.end;
229 return other.start < end && start < other.end;
236 return Range (jmax (start, other.start),
237 jmin (end, other.end));
243 return Range (jmin (start, other.start),
244 jmax (end, other.end));
250 return Range (jmin (valueToInclude, start),
251 jmax (valueToInclude, end));
266 const ValueType otherLen = rangeToConstrain.getLength();
269 : rangeToConstrain.movedToStartAt (jlimit (start, end - otherLen, rangeToConstrain.getStart()));
278 const ValueType first (*values++);
279 Range r (first, first);
281 while (--numValues > 0)
283 const ValueType v (*values++);
285 if (r.end < v) r.end = v;
286 if (v < r.start) r.start = v;
294 ValueType start{}, end{};
static Range withStartAndLength(const ValueType startValue, const ValueType length) noexcept
void setEnd(const ValueType newEnd) noexcept
Range constrainRange(Range rangeToConstrain) const noexcept
JUCE_CONSTEXPR Range withEnd(const ValueType newEnd) const noexcept
JUCE_CONSTEXPR Range getIntersectionWith(Range other) const noexcept
JUCE_CONSTEXPR Range expanded(ValueType amount) const noexcept
JUCE_CONSTEXPR Range withStart(const ValueType newStart) const noexcept
JUCE_CONSTEXPR ValueType getStart() const noexcept
JUCE_CONSTEXPR Range operator+(const ValueType amountToAdd) const noexcept
JUCE_CONSTEXPR Range movedToEndAt(const ValueType newEnd) const noexcept
JUCE_CONSTEXPR bool contains(const ValueType position) const noexcept
JUCE_CONSTEXPR Range operator-(const ValueType amountToSubtract) const noexcept
JUCE_CONSTEXPR Range withLength(const ValueType newLength) const noexcept
JUCE_CONSTEXPR bool isEmpty() const noexcept
JUCE_CONSTEXPR Range()=default
ValueType clipValue(const ValueType value) const noexcept
JUCE_CONSTEXPR ValueType getLength() const noexcept
static Range findMinAndMax(const ValueType *values, int numValues) noexcept
Range operator+=(const ValueType amountToAdd) noexcept
JUCE_CONSTEXPR Range(const ValueType startValue, const ValueType endValue) noexcept
JUCE_CONSTEXPR bool intersects(Range other) const noexcept
static JUCE_CONSTEXPR Range between(const ValueType position1, const ValueType position2) noexcept
void setLength(const ValueType newLength) noexcept
void setStart(const ValueType newStart) noexcept
Range & operator=(const Range &)=default
JUCE_CONSTEXPR Range(const Range &)=default
JUCE_CONSTEXPR bool contains(Range other) const noexcept
Range operator-=(const ValueType amountToSubtract) noexcept
JUCE_CONSTEXPR Range getUnionWith(Range other) const noexcept
JUCE_CONSTEXPR Range getUnionWith(const ValueType valueToInclude) const noexcept
static JUCE_CONSTEXPR Range emptyRange(const ValueType start) noexcept
JUCE_CONSTEXPR ValueType getEnd() const noexcept
JUCE_CONSTEXPR Range movedToStartAt(const ValueType newStart) const noexcept