Loading...
Searching...
No Matches
juce::Range< ValueType > Class Template Reference

## Detailed Description

template<typename ValueType>
class juce::Range< ValueType >

A general-purpose range object, that simply represents any linear range with a start and end point.

Note that when checking whether values fall within the range, the start value is considered to be inclusive, and the end of the range exclusive.

The templated parameter is expected to be a primitive integer or floating point type, though class types could also be used if they behave in a number-like way.

The documentation for this class was generated from the following file:

- juce_core/maths/juce_Range.h

## Public Member Functions

constexpr | Range ()=default
| Constructs an empty range.
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.
Range & | operator= (const Range &)=default
| Copies another range object.
constexpr ValueType | getStart () const noexcept
| Returns the start of the range.
constexpr ValueType | getLength () const noexcept
| Returns the length of the range.
constexpr ValueType | getEnd () const noexcept
| Returns the end of the range.
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.
constexpr Range | withStart (const ValueType newStart) const noexcept
| Returns a range with the same end as this one, but a different start.
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.
void | setEnd (const ValueType newEnd) noexcept
| Changes the end position of the range, leaving the start unchanged.
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 | 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.
constexpr Range | withLength (const ValueType newLength) const noexcept
| Returns a range with the same start as this one, but a different length.
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 | operator+= (const ValueType amountToAdd) noexcept
| Adds an amount to the start and end of the range.
Range | operator-= (const ValueType amountToSubtract) noexcept
| Subtracts an amount from the start and 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 | 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 | operator== (Range other) const noexcept
constexpr bool | operator!= (Range other) const noexcept
constexpr bool | contains (const ValueType position) const noexcept
| Returns true if the given position lies inside this range.
ValueType | clipValue (const ValueType value) const noexcept
| Returns the nearest value to the one supplied, which lies within the range.
constexpr bool | contains (Range other) const noexcept
| Returns true if the given range lies entirely inside this range.
constexpr bool | intersects (Range other) const noexcept
| Returns true if the given range intersects this one.
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 start position if they don't overlap.
constexpr Range | getUnionWith (Range other) const noexcept
| Returns the smallest range that contains both this one and the other one.
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.

## Static Public Member Functions

static constexpr Range | between (const ValueType position1, const ValueType position2) noexcept
| Returns the range that lies between two positions (in either order).
static Range | withStartAndLength (const ValueType startValue, const ValueType length) noexcept
| Returns a range with a given start and length.
static constexpr Range | emptyRange (const ValueType start) noexcept
| Returns a range with the specified start position and a length of zero.
template<typename Integral, std::enable_if_t< std::is_integral_v< Integral >, int > = 0>
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.

## Constructors and Destructors

## Range() [1/3]

template<typename ValueType>

juce::Range< ValueType >::Range | ( |  | ) |

constexpr default

Constructs an empty range.

Referenced by between(), constrainRange(), contains(), emptyRange(), expanded(), findMinAndMax(), getIntersectionWith(), getUnionWith(), getUnionWith(), intersects(), movedToEndAt(), movedToStartAt(), operator!=(), operator+(), operator+=(), operator-(), operator-=(), operator=(), operator==(), Range(), withEnd(), withLength(), withStart(), and withStartAndLength().

## Range() [2/3]

template<typename ValueType>

juce::Range< ValueType >::Range | ( | const ValueType | startValue,
|  | const ValueType | endValue )

inline constexpr noexcept

Constructs a range with given start and end values.

References juce::jmax().

## Range() [3/3]

template<typename ValueType>

juce::Range< ValueType >::Range | ( | const Range< ValueType > & |  | ) |

constexpr default

Constructs a copy of another range.

References Range().

## Member Functions

## operator=()

template<typename ValueType>

Range & juce::Range< ValueType >::operator= | ( | const Range< ValueType > & |  | ) |

default

Copies another range object.

References Range().

## between()

template<typename ValueType>

constexpr Range juce::Range< ValueType >::between | ( | const ValueType | position1,
|  | const ValueType | position2 )

inline static constexpr noexcept

Returns the range that lies between two positions (in either order).

References Range().

## withStartAndLength()

template<typename ValueType>

Range juce::Range< ValueType >::withStartAndLength | ( | const ValueType | startValue,
|  | const ValueType | length )

inline static nodiscard noexcept

Returns a range with a given start and length.

References jassert, and Range().

Referenced by juce::Rectangle< ValueType >::getHorizontalRange(), and juce::Rectangle< ValueType >::getVerticalRange().

## emptyRange()

template<typename ValueType>

constexpr Range juce::Range< ValueType >::emptyRange | ( | const ValueType | start | ) |

inline static nodiscard constexpr noexcept

Returns a range with the specified start position and a length of zero.

References Range().

## getStart()

template<typename ValueType>

ValueType juce::Range< ValueType >::getStart | ( |  | ) | const

inline constexpr noexcept

Returns the start of the range.

Referenced by juce::Reservoir::doBufferedRead(), juce::AudioData::Pointer< DataFormat, Endianness, std::conditional_t< IsInterleaved, Interleaved, NonInterleaved >, std::conditional_t< IsConst, Const, NonConst > >::findMinAndMax(), and juce::SparseSet< Type >::removeRange().

## getLength()

template<typename ValueType>

ValueType juce::Range< ValueType >::getLength | ( |  | ) | const

inline constexpr noexcept

Returns the length of the range.

Referenced by constrainRange().

## getEnd()

template<typename ValueType>

ValueType juce::Range< ValueType >::getEnd | ( |  | ) | const

inline constexpr noexcept

Returns the end of the range.

Referenced by juce::AudioData::Pointer< DataFormat, Endianness, std::conditional_t< IsInterleaved, Interleaved, NonInterleaved >, std::conditional_t< IsConst, Const, NonConst > >::findMinAndMax(), and juce::SparseSet< Type >::removeRange().

## isEmpty()

template<typename ValueType>

bool juce::Range< ValueType >::isEmpty | ( |  | ) | const

inline constexpr noexcept

Returns true if the range has a length of zero.

References juce::exactlyEqual().

Referenced by juce::SparseSet< Type >::addRange(), juce::Reservoir::doBufferedRead(), and juce::SparseSet< Type >::removeRange().

## setStart()

template<typename ValueType>

void juce::Range< ValueType >::setStart | ( | const ValueType | newStart | ) |

inline noexcept

Changes the start position of the range, leaving the end position unchanged.

If the new start position is higher than the current end of the range, the end point will be pushed along to equal it, leaving an empty range at the new position.

Referenced by juce::Reservoir::doBufferedRead().

## withStart()

template<typename ValueType>

Range juce::Range< ValueType >::withStart | ( | const ValueType | newStart | ) | const

inline nodiscard constexpr noexcept

Returns a range with the same end as this one, but a different start.

If the new start position is higher than the current end of the range, the end point will be pushed along to equal it, returning an empty range at the new position.

References juce::jmax(), and Range().

## movedToStartAt()

template<typename ValueType>

Range juce::Range< ValueType >::movedToStartAt | ( | const ValueType | newStart | ) | const

inline nodiscard constexpr noexcept

Returns a range with the same length as this one, but moved to have the given start position.

References Range().

## setEnd()

template<typename ValueType>

void juce::Range< ValueType >::setEnd | ( | const ValueType | newEnd | ) |

inline noexcept

Changes the end position of the range, leaving the start unchanged.

If the new end position is below the current start of the range, the start point will be pushed back to equal the new end point.

## withEnd()

template<typename ValueType>

Range juce::Range< ValueType >::withEnd | ( | const ValueType | newEnd | ) | const

inline nodiscard constexpr noexcept

Returns a range with the same start position as this one, but a different end.

If the new end position is below the current start of the range, the start point will be pushed back to equal the new end point.

References juce::jmin(), and Range().

## movedToEndAt()

template<typename ValueType>

Range juce::Range< ValueType >::movedToEndAt | ( | const ValueType | newEnd | ) | const

inline nodiscard constexpr noexcept

Returns a range with the same length as this one, but moved to have the given end position.

References Range().

## setLength()

template<typename ValueType>

void juce::Range< ValueType >::setLength | ( | const ValueType | newLength | ) |

inline noexcept

Changes the length of the range.

Lengths less than zero are treated as zero.

References juce::jmax().

## withLength()

template<typename ValueType>

Range juce::Range< ValueType >::withLength | ( | const ValueType | newLength | ) | const

inline nodiscard constexpr noexcept

Returns a range with the same start as this one, but a different length.

Lengths less than zero are treated as zero.

References Range().

## expanded()

template<typename ValueType>

Range juce::Range< ValueType >::expanded | ( | ValueType | amount | ) | const

inline nodiscard constexpr noexcept

Returns a range which has its start moved down and its end moved up by the given amount.

Returns
  The returned range will be (start - amount, end + amount)

References Range().

## operator+=()

template<typename ValueType>

Range juce::Range< ValueType >::operator+= | ( | const ValueType | amountToAdd | ) |

inline noexcept

Adds an amount to the start and end of the range.

References Range().

## operator-=()

template<typename ValueType>

Range juce::Range< ValueType >::operator-= | ( | const ValueType | amountToSubtract | ) |

inline noexcept

Subtracts an amount from the start and end of the range.

References Range().

## operator+()

template<typename ValueType>

Range juce::Range< ValueType >::operator+ | ( | const ValueType | amountToAdd | ) | const

inline constexpr noexcept

Returns a range that is equal to this one with an amount added to its start and end.

References Range().

## operator-()

template<typename ValueType>

Range juce::Range< ValueType >::operator- | ( | const ValueType | amountToSubtract | ) | const

inline constexpr noexcept

Returns a range that is equal to this one with the specified amount subtracted from its start and end.

References Range().

## operator==()

template<typename ValueType>

bool juce::Range< ValueType >::operator== | ( | Range< ValueType > | other | ) | const

inline constexpr noexcept

References Range().

Referenced by operator!=().

## operator!=()

template<typename ValueType>

bool juce::Range< ValueType >::operator!= | ( | Range< ValueType > | other | ) | const

inline constexpr noexcept

References operator==(), and Range().

## contains() [1/2]

template<typename ValueType>

bool juce::Range< ValueType >::contains | ( | const ValueType | position | ) | const

inline constexpr noexcept

Returns true if the given position lies inside this range.

When making this comparison, the start value is considered to be inclusive, and the end of the range exclusive.

Referenced by juce::SparseSet< Type >::removeRange().

## clipValue()

template<typename ValueType>

ValueType juce::Range< ValueType >::clipValue | ( | const ValueType | value | ) | const

inline noexcept

Returns the nearest value to the one supplied, which lies within the range.

References juce::jlimit().

## contains() [2/2]

template<typename ValueType>

bool juce::Range< ValueType >::contains | ( | Range< ValueType > | other | ) | const

inline constexpr noexcept

Returns true if the given range lies entirely inside this range.

References Range().

## intersects()

template<typename ValueType>

bool juce::Range< ValueType >::intersects | ( | Range< ValueType > | other | ) | const

inline constexpr noexcept

Returns true if the given range intersects this one.

References Range().

## getIntersectionWith()

template<typename ValueType>

Range juce::Range< ValueType >::getIntersectionWith | ( | Range< ValueType > | other | ) | const

inline nodiscard constexpr noexcept

Returns the range that is the intersection of the two ranges, or an empty range with an undefined start position if they don't overlap.

References juce::jmax(), juce::jmin(), and Range().

Referenced by juce::Reservoir::doBufferedRead().

## getUnionWith() [1/2]

template<typename ValueType>

Range juce::Range< ValueType >::getUnionWith | ( | Range< ValueType > | other | ) | const

inline nodiscard constexpr noexcept

Returns the smallest range that contains both this one and the other one.

References juce::jmax(), juce::jmin(), and Range().

## getUnionWith() [2/2]

template<typename ValueType>

Range juce::Range< ValueType >::getUnionWith | ( | const ValueType | valueToInclude | ) | const

inline nodiscard constexpr noexcept

Returns the smallest range that contains both this one and the given value.

References juce::jmax(), juce::jmin(), and Range().

## constrainRange()

template<typename ValueType>

Range juce::Range< ValueType >::constrainRange | ( | Range< ValueType > | rangeToConstrain | ) | const

inline noexcept

Returns a given range, after moving it forwards or backwards to fit it within this range.

If the supplied range has a greater length than this one, the return value will be this range.

Otherwise, if the supplied range is smaller than this one, the return value will be the new range, shifted forwards or backwards so that it doesn't extend beyond this one, but keeping its original length.

References getLength(), juce::jlimit(), and Range().

## findMinAndMax()

template<typename ValueType>
template<typename Integral, std::enable_if_t< std::is_integral_v< Integral >, int > = 0>

Range juce::Range< ValueType >::findMinAndMax | ( | const ValueType * | values,
|  | Integral | numValues )

inline static noexcept

Scans an array of values for its min and max, and returns these as a Range.

References Range().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited