38template <
typename ValueType>
68 jassert (length >= ValueType());
75 return Range (start, start);
83 constexpr inline ValueType
getLength()
const noexcept {
return end - start; }
86 constexpr inline ValueType
getEnd()
const noexcept {
return end; }
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;
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);
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{};
A general-purpose range object, that simply represents any linear range with a start and end point.
static Range withStartAndLength(const ValueType startValue, const ValueType length) noexcept
Returns a range with a given start and length.
void setEnd(const ValueType newEnd) noexcept
Changes the end position of the range, leaving the start unchanged.
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.
Range constrainRange(Range rangeToConstrain) const noexcept
Returns a given range, after moving it forwards or backwards to fit it within this range.
constexpr ValueType getStart() const noexcept
Returns the start of the range.
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...
constexpr bool contains(Range other) const noexcept
Returns true if the given range lies entirely inside this range.
constexpr bool isEmpty() const noexcept
Returns true if the range has a length of zero.
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...
static constexpr Range emptyRange(const ValueType start) noexcept
Returns a range with the specified start position and a length of zero.
constexpr bool intersects(Range other) const noexcept
Returns true if the given range intersects this one.
constexpr ValueType getEnd() const noexcept
Returns the end of the range.
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.
constexpr Range withEnd(const ValueType newEnd) const noexcept
Returns a range with the same start position as this one, but a different end.
constexpr Range(const ValueType startValue, const ValueType endValue) noexcept
Constructs a range with given start and end values.
constexpr Range(const Range &)=default
Constructs a copy of another range.
constexpr Range getUnionWith(Range other) const noexcept
Returns the smallest range that contains both this one and the other one.
static Range findMinAndMax(const ValueType *values, Integral numValues) noexcept
Scans an array of values for its min and max, and returns these as a Range.
ValueType clipValue(const ValueType value) const noexcept
Returns the nearest value to the one supplied, which lies within the range.
static constexpr Range between(const ValueType position1, const ValueType position2) noexcept
Returns the range that lies between two positions (in either order).
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.
constexpr Range withLength(const ValueType newLength) const noexcept
Returns a range with the same start as this one, but a different length.
constexpr Range getUnionWith(const ValueType valueToInclude) const noexcept
Returns the smallest range that contains both this one and the given value.
Range operator+=(const ValueType amountToAdd) noexcept
Adds an amount to the start and end of the range.
void setLength(const ValueType newLength) noexcept
Changes the length of the range.
void setStart(const ValueType newStart) noexcept
Changes the start position of the range, leaving the end position unchanged.
constexpr ValueType getLength() const noexcept
Returns the length of the range.
Range & operator=(const Range &)=default
Copies another range object.
constexpr bool contains(const ValueType position) const noexcept
Returns true if the given position lies inside this range.
Range operator-=(const ValueType amountToSubtract) noexcept
Subtracts an amount from the start and end of the range.
constexpr Range()=default
Constructs an empty range.
constexpr Range withStart(const ValueType newStart) const noexcept
Returns a range with the same end as this one, but a different start.
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.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr bool exactlyEqual(Type a, Type b)
Equivalent to operator==, but suppresses float-equality warnings.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...