A general-purpose range object, that simply represents any linear range with a start and end point. More...
Public Member Functions | |
| Range () noexcept | |
| Constructs an empty range. | |
| Range (const ValueType start_, const ValueType end_) noexcept | |
| Constructs a range with given start and end values. | |
| Range (const Range &other) noexcept | |
| Constructs a copy of another range. | |
| Range & | operator= (const Range &other) noexcept |
| Copies another range object. | |
| ~Range () noexcept | |
| Destructor. | |
| ValueType | getStart () const noexcept |
| Returns the start of the range. | |
| ValueType | getLength () const noexcept |
| Returns the length of the range. | |
| ValueType | getEnd () const noexcept |
| Returns the end of the range. | |
| 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. | |
| Range | withStart (const ValueType newStart) const noexcept |
| Returns a range with the same end as this one, but a different start. | |
| 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. | |
| Range | withEnd (const ValueType newEnd) const noexcept |
| Returns a range with the same start position as this one, but a different end. | |
| Range | movedToEndAt (const ValueType newEnd) const noexcept |
| Returns a range with the same length as this one, but moved to have the given start position. | |
| void | setLength (const ValueType newLength) noexcept |
| Changes the length of the range. | |
| Range | withLength (const ValueType newLength) const noexcept |
| Returns a range with the same start as this one, but a different length. | |
| const Range & | operator+= (const ValueType amountToAdd) noexcept |
| Adds an amount to the start and end of the range. | |
| const Range & | operator-= (const ValueType amountToSubtract) noexcept |
| Subtracts an amount from the start and end of the range. | |
| 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. | |
| 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. | |
| bool | operator== (const Range &other) const noexcept |
| bool | operator!= (const Range &other) const noexcept |
| 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. | |
| bool | contains (const Range &other) const noexcept |
| Returns true if the given range lies entirely inside this range. | |
| bool | intersects (const Range &other) const noexcept |
| Returns true if the given range intersects this one. | |
| Range | getIntersectionWith (const 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. | |
| Range | getUnionWith (const Range &other) const noexcept |
| Returns the smallest range that contains both this one and the other one. | |
| Range | constrainRange (const 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 Range | between (const ValueType position1, const ValueType position2) noexcept |
| Returns the range that lies between two positions (in either order). | |
| static Range | emptyRange (const ValueType start) noexcept |
| Returns a range with the specified start position and a length of zero. | |
A general-purpose range object, that simply represents any linear range with a start and end point.
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.
Constructs an empty range.
Referenced by Range< int >::between(), Range< int >::emptyRange(), Range< int >::getIntersectionWith(), Range< int >::getUnionWith(), Range< int >::movedToEndAt(), Range< int >::movedToStartAt(), Range< int >::operator+(), Range< int >::operator-(), Range< int >::withEnd(), Range< int >::withLength(), and Range< int >::withStart().
| Range< ValueType >::Range | ( | const ValueType | start_, |
| const ValueType | end_ | ||
| ) |
Constructs a range with given start and end values.
Constructs a copy of another range.
| Range& Range< ValueType >::operator= | ( | const Range< ValueType > & | other | ) |
Copies another range object.
| static Range Range< ValueType >::between | ( | const ValueType | position1, |
| const ValueType | position2 | ||
| ) | [static] |
Returns the range that lies between two positions (in either order).
| static Range Range< ValueType >::emptyRange | ( | const ValueType | start | ) | [static] |
Returns a range with the specified start position and a length of zero.
Returns the start of the range.
Referenced by SparseSet< int >::addRange(), SparseSet< int >::containsRange(), SparseSet< int >::overlapsRange(), and SparseSet< int >::removeRange().
Returns the length of the range.
Referenced by SparseSet< int >::addRange(), Range< int >::constrainRange(), SparseSet< int >::containsRange(), SparseSet< int >::overlapsRange(), and SparseSet< int >::removeRange().
Returns the end of the range.
Referenced by SparseSet< int >::addRange(), SparseSet< int >::containsRange(), SparseSet< int >::overlapsRange(), and SparseSet< int >::removeRange().
Returns true if the range has a length of zero.
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.
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.
| Range Range< ValueType >::movedToStartAt | ( | const ValueType | newStart | ) | const |
Returns a range with the same length as this one, but moved to have the given start position.
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.
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.
| Range Range< ValueType >::movedToEndAt | ( | const ValueType | newEnd | ) | const |
Returns a range with the same length as this one, but moved to have the given start position.
Changes the length of the range.
Lengths less than zero are treated as zero.
| Range Range< ValueType >::withLength | ( | const ValueType | newLength | ) | const |
Returns a range with the same start as this one, but a different length.
Lengths less than zero are treated as zero.
| const Range& Range< ValueType >::operator+= | ( | const ValueType | amountToAdd | ) |
Adds an amount to the start and end of the range.
| const Range& Range< ValueType >::operator-= | ( | const ValueType | amountToSubtract | ) |
Subtracts an amount from the start and end of the range.
| Range Range< ValueType >::operator+ | ( | const ValueType | amountToAdd | ) | const |
Returns a range that is equal to this one with an amount added to its start and end.
| Range Range< ValueType >::operator- | ( | const ValueType | amountToSubtract | ) | const |
Returns a range that is equal to this one with the specified amount subtracted from its start and end.
| bool Range< ValueType >::operator== | ( | const Range< ValueType > & | other | ) | const |
| bool Range< ValueType >::operator!= | ( | const Range< ValueType > & | other | ) | const |
Returns true if the given position lies inside this range.
Returns the nearest value to the one supplied, which lies within the range.
| bool Range< ValueType >::contains | ( | const Range< ValueType > & | other | ) | const |
Returns true if the given range lies entirely inside this range.
| bool Range< ValueType >::intersects | ( | const Range< ValueType > & | other | ) | const |
Returns true if the given range intersects this one.
| Range Range< ValueType >::getIntersectionWith | ( | const Range< ValueType > & | other | ) | const |
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.
| Range Range< ValueType >::getUnionWith | ( | const Range< ValueType > & | other | ) | const |
Returns the smallest range that contains both this one and the other one.
| Range Range< ValueType >::constrainRange | ( | const Range< ValueType > & | rangeToConstrain | ) | const |
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.