42 template <
typename ValueType>
48 JUCE_CONSTEXPR
Range() =
default;
51 JUCE_CONSTEXPR
Range (
const ValueType startValue,
const ValueType endValue) noexcept
52 : start (startValue), end (jmax (startValue, endValue))
63 JUCE_CONSTEXPR
static Range between (
const ValueType position1,
const ValueType position2) noexcept
65 return position1 < position2 ?
Range (position1, position2)
66 :
Range (position2, position1);
72 jassert (length >= ValueType());
73 return Range (startValue, startValue + length);
79 return Range (start, start);
84 JUCE_CONSTEXPR
inline ValueType
getStart() const noexcept {
return start; }
87 JUCE_CONSTEXPR
inline ValueType
getLength() const noexcept {
return end - start; }
90 JUCE_CONSTEXPR
inline ValueType
getEnd() const noexcept {
return end; }
93 JUCE_CONSTEXPR
inline bool isEmpty() const noexcept {
return start == end; }
113 return Range (newStart, jmax (newStart, end));
119 return Range (newStart, end + (newStart - start));
126 void setEnd (
const ValueType newEnd) noexcept
139 return Range (jmin (start, newEnd), newEnd);
145 return Range (start + (newEnd - end), newEnd);
153 end = start + jmax (ValueType(), newLength);
161 return Range (start, start + newLength);
170 return Range (start - amount, end + amount);
177 start += amountToAdd;
185 start -= amountToSubtract;
186 end -= amountToSubtract;
195 return Range (start + amountToAdd, end + amountToAdd);
202 return Range (start - amountToSubtract, end - amountToSubtract);
205 JUCE_CONSTEXPR
bool operator== (
Range other)
const noexcept {
return start == other.start && end == other.end; }
206 JUCE_CONSTEXPR
bool operator!= (
Range other)
const noexcept {
return start != other.start || end != other.end; }
213 JUCE_CONSTEXPR
bool contains (
const ValueType position)
const noexcept
215 return start <= position && position < end;
219 ValueType
clipValue (
const ValueType value)
const noexcept
221 return jlimit (start, end, value);
227 return start <= other.start && end >= other.end;
233 return other.start < end && start < other.end;
240 return Range (jmax (start, other.start),
241 jmin (end, other.end));
247 return Range (jmin (start, other.start),
248 jmax (end, other.end));
254 return Range (jmin (valueToInclude, start),
255 jmax (valueToInclude, end));
270 const ValueType otherLen = rangeToConstrain.
getLength();
273 : rangeToConstrain.movedToStartAt (jlimit (start, end - otherLen, rangeToConstrain.getStart()));
282 const ValueType first (*values++);
283 Range r (first, first);
285 while (--numValues > 0)
287 const ValueType v (*values++);
289 if (r.end < v) r.end = v;
290 if (v < r.start) r.start = v;
298 ValueType start{}, end{};
JUCE_CONSTEXPR Range operator+(const ValueType amountToAdd) const noexcept
Returns a range that is equal to this one with an amount added to its start and end.
void setEnd(const ValueType newEnd) noexcept
Changes the end position of the range, leaving the start unchanged.
JUCE_CONSTEXPR Range getUnionWith(const ValueType valueToInclude) const noexcept
Returns the smallest range that contains both this one and the given value.
Range constrainRange(Range rangeToConstrain) const noexcept
Returns a given range, after moving it forwards or backwards to fit it within this range...
JUCE_CONSTEXPR Range movedToEndAt(const ValueType newEnd) const noexcept
Returns a range with the same length as this one, but moved to have the given end position...
void setLength(const ValueType newLength) noexcept
Changes the length of the range.
JUCE_CONSTEXPR Range getUnionWith(Range other) const noexcept
Returns the smallest range that contains both this one and the other one.
Range operator+=(const ValueType amountToAdd) noexcept
Adds an amount to the start and end of the range.
JUCE_CONSTEXPR Range operator-(const ValueType amountToSubtract) const noexcept
Returns a range that is equal to this one with the specified amount subtracted from its start and end...
JUCE_CONSTEXPR bool contains(const ValueType position) const noexcept
Returns true if the given position lies inside this range.
JUCE_CONSTEXPR Range withLength(const ValueType newLength) const noexcept
Returns a range with the same start as this one, but a different length.
Range & operator=(const Range &)=default
Copies another range object.
JUCE_CONSTEXPR Range movedToStartAt(const ValueType newStart) const noexcept
Returns a range with the same length as this one, but moved to have the given start position...
JUCE_CONSTEXPR bool intersects(Range other) const noexcept
Returns true if the given range intersects this one.
JUCE_CONSTEXPR Range()=default
Constructs an empty range.
JUCE_CONSTEXPR ValueType getEnd() const noexcept
Returns the end of the range.
JUCE_CONSTEXPR Range withStart(const ValueType newStart) const noexcept
Returns a range with the same end as this one, but a different start.
ValueType clipValue(const ValueType value) const noexcept
Returns the nearest value to the one supplied, which lies within the range.
static JUCE_CONSTEXPR Range between(const ValueType position1, const ValueType position2) noexcept
Returns the range that lies between two positions (in either order).
JUCE_CONSTEXPR Range expanded(ValueType amount) const noexcept
Returns a range which has its start moved down and its end moved up by the given amount.
static Range withStartAndLength(const ValueType startValue, const ValueType length) noexcept
Returns a range with a given start and length.
static Range findMinAndMax(const ValueType *values, int numValues) noexcept
Scans an array of values for its min and max, and returns these as a Range.
Range operator-=(const ValueType amountToSubtract) noexcept
Subtracts an amount from the start and end of the range.
JUCE_CONSTEXPR ValueType getLength() const noexcept
Returns the length of the range.
JUCE_CONSTEXPR bool isEmpty() const noexcept
Returns true if the range has a length of zero.
void setStart(const ValueType newStart) noexcept
Changes the start position of the range, leaving the end position unchanged.
JUCE_CONSTEXPR Range withEnd(const ValueType newEnd) const noexcept
Returns a range with the same start position as this one, but a different end.
JUCE_CONSTEXPR ValueType getStart() const noexcept
Returns the start of the range.
JUCE_CONSTEXPR Range(const ValueType startValue, const ValueType endValue) noexcept
Constructs a range with given start and end values.
JUCE_CONSTEXPR bool contains(Range other) const noexcept
Returns true if the given range lies entirely inside this range.
static JUCE_CONSTEXPR Range emptyRange(const ValueType start) noexcept
Returns a range with the specified start position and a length of zero.
JUCE_CONSTEXPR Range getIntersectionWith(Range other) const noexcept
Returns the range that is the intersection of the two ranges, or an empty range with an undefined sta...
A general-purpose range object, that simply represents any linear range with a start and end point...