38template <
typename ValueType>
47 constexpr Range (
const ValueType startValue,
const ValueType endValue) noexcept
48 : start (startValue), end (jmax (startValue, endValue))
59 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 constexpr inline ValueType
getStart() const noexcept {
return start; }
83 constexpr inline ValueType
getLength() const noexcept {
return end - start; }
86 constexpr inline ValueType
getEnd() const noexcept {
return end; }
89 constexpr inline bool isEmpty() const noexcept {
return exactlyEqual (start, end); }
96 void setStart (
const ValueType newStart)
noexcept
107 [[nodiscard]]
constexpr Range withStart (
const ValueType newStart)
const noexcept
109 return Range (newStart, jmax (newStart, end));
115 return Range (newStart, end + (newStart - start));
122 void setEnd (
const ValueType newEnd)
noexcept
133 [[nodiscard]]
constexpr Range withEnd (
const ValueType newEnd)
const 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 constexpr bool operator== (
Range other)
const noexcept
203 const auto tie = [] (
const Range& r) {
return std::tie (r.start, r.end); };
204 return tie (*
this) == tie (other);
207 constexpr bool operator!= (
Range other)
const noexcept {
return ! operator== (other); }
214 constexpr bool contains (
const ValueType position)
const noexcept
216 return start <= position && position < end;
220 ValueType
clipValue (
const ValueType value)
const noexcept
222 return jlimit (start, end, value);
228 return start <= other.start && end >= other.end;
234 return other.start < end && start < other.end;
241 return Range (jmax (start, other.start),
242 jmin (end, other.end));
248 return Range (jmin (start, other.start),
249 jmax (end, other.end));
255 return Range (jmin (valueToInclude, start),
256 jmax (valueToInclude, end));
271 const ValueType otherLen = rangeToConstrain.getLength();
274 : rangeToConstrain.movedToStartAt (jlimit (start, end - otherLen, rangeToConstrain.getStart()));
278 template <
typename Integral, std::enable_if_t<std::is_
integral_v<Integral>,
int> = 0>
284 const ValueType first (*values++);
285 Range r (first, first);
287 while (--numValues > 0)
289 const ValueType v (*values++);
291 if (r.end < v) r.end = v;
292 if (v < r.start) r.start = v;
300 ValueType start{}, end{};
static Range withStartAndLength(const ValueType startValue, const ValueType length) noexcept
void setEnd(const ValueType newEnd) noexcept
constexpr Range expanded(ValueType amount) const noexcept
Range constrainRange(Range rangeToConstrain) const noexcept
constexpr ValueType getStart() const noexcept
constexpr Range operator-(const ValueType amountToSubtract) const noexcept
constexpr bool contains(Range other) const noexcept
constexpr bool isEmpty() const noexcept
constexpr Range getIntersectionWith(Range other) const noexcept
static constexpr Range emptyRange(const ValueType start) noexcept
constexpr bool intersects(Range other) const noexcept
constexpr ValueType getEnd() const noexcept
constexpr Range operator+(const ValueType amountToAdd) const noexcept
constexpr Range withEnd(const ValueType newEnd) const noexcept
constexpr Range(const ValueType startValue, const ValueType endValue) noexcept
constexpr Range(const Range &)=default
constexpr Range getUnionWith(Range other) const noexcept
static Range findMinAndMax(const ValueType *values, Integral numValues) noexcept
ValueType clipValue(const ValueType value) const noexcept
static constexpr Range between(const ValueType position1, const ValueType position2) noexcept
constexpr Range movedToStartAt(const ValueType newStart) const noexcept
constexpr Range withLength(const ValueType newLength) const noexcept
constexpr Range getUnionWith(const ValueType valueToInclude) const noexcept
Range operator+=(const ValueType amountToAdd) noexcept
void setLength(const ValueType newLength) noexcept
void setStart(const ValueType newStart) noexcept
constexpr ValueType getLength() const noexcept
Range & operator=(const Range &)=default
constexpr bool contains(const ValueType position) const noexcept
Range operator-=(const ValueType amountToSubtract) noexcept
constexpr Range()=default
constexpr Range withStart(const ValueType newStart) const noexcept
constexpr Range movedToEndAt(const ValueType newEnd) const noexcept